Info

This question is closed. Reopen it to edit or answer.

how to create a loop

1 view (last 30 days)
faizan
faizan on 6 Mar 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
i have matrix vENU size 6 400 i want to make a loop . i want make a loop for 1 to 400 ... i want to get 400 value of roll pitch and yaw... plz help me i am new here... thanks. how to call loop here? that loop run for every col, here is code
if true
%
vSlaveAntLocal1=vENU(1:3);
vSlaveAntLocal2=vENU(4:6);
%%~~~~~~~~~~~~ Step 1 ~~~~~~~~~~~~~~~
%%Using Ant 2 to derive yaw and pitch
%%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x2=vSlaveAntLocal1(1);
y2=vSlaveAntLocal1(2);
z2=vSlaveAntLocal1(3);
x3=vSlaveAntLocal2(1);
y3=vSlaveAntLocal2(2);
z3=vSlaveAntLocal2(3);
%%Get yaw
yaw_arc=-atan(x2/y2);
yaw_deg=GetAngleDeg(yaw_arc)
%yaw_degAD = [yaw_degAD yaw_deg]
%%Get pitch
pitch_arc=atan(z2/sqrt(x2*x2+y2*y2));
pitch_deg=GetAngleDeg(pitch_arc)
%pitch_degAD = [pitch_degAD pitch_deg]
%%~~~~~~~~~~~~ Step 2 ~~~~~~~~~~~~~~~
%%Rotate Ant 3 to derive roll
%%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%%1st rotation matrix-- rotate about Z by yaw
R3=[cos(yaw_arc) sin(yaw_arc) 0;...
-sin(yaw_arc) cos(yaw_arc) 0;...
0 0 1];
%%2nd rotation matrix-- rotate about X' by pitch
R1=[1 0 0;
0 cos(pitch_arc) sin(pitch_arc);
0 -sin(pitch_arc) cos(pitch_arc)];
%%Now rotate the Ant 3
mRotation1=R3*[x3 y3 z3]';
mRotation2=R1*mRotation1;
%%~~~~~~~~~~~~ Step 2 ~~~~~~~~~~~~~~~
%%Get roll
%%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%%Roll
roll_arc=-atan(mRotation2(3)/mRotation2(1));
roll_deg=GetAngleDeg(roll_arc)
%roll_degAD = [roll_degAD roll_deg]
%Rollpitchyaw = [yaw_degAD,roll_degAD,pitch_degAD]
%end
end

Answers (1)

ChristianW
ChristianW on 6 Mar 2013
vENU = rand(6,400); % random data generation
N = size(vENU,2); % = 400 steps (in your example)
yaw_deg = zeros(1,N); % preallocation (only for speed)
for i = 1:N
vSlaveAntLocal1=vENU(1:3,i);
x2=vSlaveAntLocal1(1);
y2=vSlaveAntLocal1(2);
yaw_arc=-atan(x2/y2);
yaw_deg(i) = yaw_arc*180/pi;
end
Analogously for the other angles.

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!