Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,922 Registered: 12/7/04
Re: Vector Coding
Posted: Nov 26, 2013 1:56 PM

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.

Date Subject Author
11/26/13 Douglas
11/26/13 Derek Goring
11/26/13 Douglas
11/26/13 Derek Goring
11/26/13 Douglas
11/26/13 Derek Goring
11/26/13 Roger Stafford