how to save outputs of a loop in vectors to use later ??? urgent please help
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
Matt Fig
el 12 de Mayo de 2011
I don't see a th2. Assuming you meant one point per loop iteration...
l1=0;%input('input l1: ');
l2=3;%input('input l2: ');
l3=8;%input('input l3: ');
w2=20.9;%;input('input w2: ');
a4 = zeros(1,361);
for ii=0:360
a = ii*(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(ii+1) = -(g*(alp3)+c*(w2^2)+h*(w3^2));
end
plot(0:360,a4)
4 comentarios
Matt Fig
el 12 de Mayo de 2011
To see a4, simply type:
a4
at the end of the loop. This will dump the vector to the screen.
Más respuestas (1)
Ahmad
el 12 de Mayo de 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 comentarios
Ahmad
el 12 de Mayo de 2011
I would completely go for the answer Mr. Matt Fig Suggested.
Thanks for your help Sir.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!