Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

atan2 of successive point in an Array

Asked by Rica on 26 Jun 2013

Hi all!

how could i calculate the atan2 for this Vector in this way:

 %%
A=[a0 a1 a2 a3 a4......]
atan_vec=[atan2(a1,a0) atan2(a3,a2) atan2(a4,a3),......]

thank you for the Help

0 Comments

Rica

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 26 Jun 2013
Edited by Andrei Bobrov on 26 Jun 2013
out = atan2(A(2:end),A(1:end-1));

or

for jj = numel(A)-1:-1:1
    out(jj,1) = atan2(A(jj+1),A(jj));
end

or

out = arrayfun(@(ii)atan2(A(ii+1),A(ii)),(1:numel(A)-1)');

or

a = hankel(A(1:end-1),A(end-1:end));
out = atan2(a(:,2),a(:,1));

0 Comments

Andrei Bobrov

Contact us