Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Vector Coding
Replies: 6   Last Post: Nov 26, 2013 11:57 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Douglas

Posts: 3
Registered: 11/26/13
Re: Vector Coding
Posted: Nov 26, 2013 8:24 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

TideMan <mulgor@gmail.com> wrote in message <7ea51940-a30f-4a3a-9f7d-23fc095758b0@googlegroups.com>...
> On Wednesday, November 27, 2013 8:36:08 AM UTC+13, Douglas wrote:
> > I apologize for the inaccuracy in my typing. Gamma was a matrix (gamma(i)) and the atan2 argument had a comma rather than the division symbol.
> >
> >
> >
> > After making the suggested changes, the issue of vertical asymptotes still exists. The revised code is listed below.
> >
> >
> >
> > gamma=zeros(m-1,1);
> >
> >
> >
> > for row=1:m-2
> >
> > gamma(row)=atan2((y(row+1)-y(row)),(x(row+1)-x(row)));
> >
> > end
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > TideMan <mulgor@gmail.com> wrote in message <b265bf79-061a-4ef4-98ec-6ff04a8bfdf6@googlegroups.com>...
> >

> > > On Wednesday, November 27, 2013 4:00:20 AM UTC+13, Douglas wrote:
> >
> > > > Roger,
> >
> > > >
> >
> > > > I am trying to conduct an analysis of coordination between two adjacent segments called Vector coding (Chang et al., 2008; Journal of Biomechanics). The coupling angle is defined as the inverse tangent of the change in y divided by the change in x (see code below). However, I cannot condition my data such that I avoid the vertical asymptotes of the atan2 function. Can you please offer some suggestions.
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > x and y are single column arrays with length m.
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > [m,n]=size(x);
> >
> > > >
> >
> > > >
> >
> > > >
> >
> > > > for i=1:m-1
> >
> > > >
> >
> > > > gamma=atan2((y(i+1)-y(i))/(x(i+1)-x(i)))
> >
> > > >
> >
> > > > end
> >
> > >
> >
> > > There are several things wrong with your code:
> >
> > > 1. gamma gets over-written each time through the loop, you should use gamma(i)
> >
> > > 2. By default, i and j are sqrt(-1). You should not use i or j as indexes, especially for this particular task which is often easier using complex numbers.
> >
> > > 3. atan2 takes two arguments. You have only one. You will find that if you use atan2 properly, it handles atan2(1,0) OK.
> >
> > > 4. if you use gamma(i), you need to preallocate storage with gamma=zeros(m-1,1); before the loop.
>
> Please do not top post, it makes the thread hard to follow.
> Put your reply UNDERNEATH.
>
> I don't understand why you have asymptote problems with atan2.
> In my version of Matlab, it doesn't matter what I put in atan2, it works.
> atan2(0,1) is OK
> atan2(1,0) is OK
> atan2(inf,inf) is OK
> atan2(0,0) is OK
> Can you be more specific as to when atan2 fails?
>
> BTW, you don't need a loop for your calculations, try:
> gamma=angle(diff(x) + i*diff(y));
> or
> gamma=atan2(diff(y),diff(x));




My apologies. I still have vertical "deformities" to what should be a smooth curve. If you like, I am more than willing to send you the data and an image of the atan2 curve produced from the atan2(diff(y),diff(x)) calculation. I do not know if I can upload those to this site.

It appears the deformity occurs when the atan2 data approaches 180 degrees.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.