how to save outputs of a loop in vectors to use later ??? urgent please help
Mostra commenti meno recenti
iam making a loop to calculate some values for theta from 0:360 but i cant plot correctly it always plots for me the last point out from the loop and i want to print the values corresponding the theta in the loop for my project and plot it here is the code
l1=0;%input('input l1: ');
l2=3;%input('input l2: ');
l3=8;%input('input l3: ');
w2=20.9;%;input('input w2: ');
for i=0:360
a=i*(pi/180);
b=l2*sin(a);
c=l2*cos(a);
d=-(asin((l1+a)/l3));
th3=d*(180/pi)*i;
e=l2*sin(d);
f=l2*cos(d);
g=l3*sin(d);
h=l3*cos(d);
l4=c+f;
w3=-w2*(c/f);
v4=-w2*(b)-w3*(g);
alp3=(b*(w2^2)+g*(w3^2))/h;
a4=[-(g*(alp3)+c*(w2^2)+h*(w3^2))];
plot (i,a4)
end
here i want to plot a4,th2 but plots only one point and i want to the 360 values of the a4? but how
thanks in advance
Risposta accettata
Più risposte (1)
Ahmad
il 12 Mag 2011
Hi, Where is th2. Anyways, I do not know what is this meant to do but try this :
th3_vect=zeros(0);
a4_vect=zeros(0);
for i=0:36
a=i*(pi/180);
b=l2*sin(a);
c=l2*cos(a);
d=-(asin((l1+a)/l3));
th3=d*(180/pi)*i;
e=l2*sin(d);
f=l2*cos(d);
g=l3*sin(d);
h=l3*cos(d);
l4=c+f;
w3=-w2*(c/f);
v4=-w2*(b)-w3*(g);
alp3=(b*(w2^2)+g*(w3^2))/h;
a4=[-(g*(alp3)+c*(w2^2)+h*(w3^2))];
th3_vect(length(th3_vect)+1)=th3;
a4_vect(length(a4_vect)+1)=a4;
end
plot (th3_vect,a4_vect)
3 Commenti
Matt Fig
il 12 Mag 2011
I would not recommend growing arrays in the loop like this. The effect is to slow the code down. For such a small final length this may not matter a whole lot, but for larger lengths this will really slow things down...
Ahmad
il 12 Mag 2011
I would completely go for the answer Mr. Matt Fig Suggested.
Thanks for your help Sir.
bassam imam
il 13 Mag 2011
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!