How can i store multiple values obtained from a loop in a matrix?

2 views (last 30 days)
What I want to achieve is to store for example theta_degrees as a matrix where the rows will be the values obtained from the first while loop and every time the first while loop is not true another row to be generated in order to store another series of values. The same i want to do with theta_degrees2 and Moment.
Currently i can store the values obtained from the first while loop but i cannot create an array in order to store all the values for each variable as an array. I want to do this in order to create a surface graph.
This is my code - forget about the stuff at the beginning
clc
W_load=350 %Load on the pannier
Area=(0.893*(0.283+0.420+0.221))-((0.893-0.809)*(0.283+0.221));
density=9760;%Density of Material
Volume_boom=((0.6*2+0.45*2)*0.01)*9.33;
W2=density*Volume_boom;
Volume_pannier=1.943*(0.283+0.221+0.42)*0.893;
Volume_pannier_s=((1.943-1.859)*(0.283+0.221)*0.893)+(0.893-0.809)*(0.283+0.221)*1.859;
Volume_pannier_h=(0.809-0.02)*(0.283+0.221+0.42-0.04)*(1.859-0.02);
Volume_pannier_f=Volume_pannier-Volune_pannier_s-Volume_pannier_h;
Wpannier=density*Volume_pannier_f;
Volume_Outer=(1.4*2+0.55*2)*0.01*9.9;
W1=density*Volume_Outer;
d1=2.42;
d2=2.73;
theta_in=61*pi/180;
theta_2=0;
theta_degrees=0;
theta_2degrees=0;
theta_2_degrees=0;
Moment=0;
k=0; %counter 1
f=0; %counter 2
while(theta_2<2.18166) theta_in=61*pi/180;
while(theta_in<1.9373) k=k+1;
if(theta_2==0)
Moment(k)=sin(theta_in)*(W1*d1+W2*(d1+d2)+Wpannier*(2*d1+2*d2));
theta_in=theta_in+(pi/180); %this is essentially theta_degrees but in rads
theta_degrees(k)=theta_in*180/pi;
elseif (theta_2>0 & theta_2<1.570796327)
Moment(k)=sin(theta_in+theta_2)*(W1*d1+W2*(d1+d2)+Wpannier*(2*d1+2*d2));
theta_in=theta_in+(pi/180);
theta_degrees(k)=theta_in*180/pi;
elseif (theta_2==1.57079)
Moment(k)=sin(theta_in)*(W1*d1+W2*(d1+d2)+Wpannier*(2*d1+2*d2));
theta_in=theta_in+(pi/180);
theta_degrees(k)=theta_in*180/pi;
elseif (theta_2>1.57079)
theta_3= theta_2-90;
phi=90-theta_2;
Moment(k)=sin(theta_in-phi)*(W1*d1+W2*(d1+d2)+Wpannier*(2*d1+2*d2));
theta_in=theta_in+(pi/180);
theta_degrees(k)=theta_in*180/pi;
else (theta_2>2.1817)
disp('The angle is too high');
end
theta_2degrees(k)=theta_2*180/pi;
end
theta_2=theta_2+pi/180;
theta_2_degrees=theta_2*180/pi;
f=f+1;
%I tried to store the values as an array like this but the fth
%value of theta_degrees is displayed.
%mat(f,:)=theta_degrees(f)
%mat2(f,:)=theta_2degrees(k);
%mat3(f,:)=Moment(k); end
plot3(theta_degrees,theta_2degrees,Moment,'-g','linewidth',2);

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!