Info

# how to create a loop

1 view (last 30 days)
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)
%%Get pitch
pitch_arc=atan(z2/sqrt(x2*x2+y2*y2));
pitch_deg=GetAngleDeg(pitch_arc)
%%~~~~~~~~~~~~ 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)
%end
end

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.