consider preallocating for speed

1 visualización (últimos 30 días)
Shaghayegh Ghandali
Shaghayegh Ghandali el 30 de Mzo. de 2020
Comentada: Shaghayegh Ghandali el 30 de Mzo. de 2020
so i was wondering is there any way for fixing it i just don't want to use this :
theta_2= zeros(i,1);
th_2 =zeros(i,1);
A_X =zeros(i,1);
A_Y=zeros(i,1);
for each and indivual outputs before my for loop
this is my script
for i=1:360
theta_2(1)= 0; % initial angle for link 2
theta_2(i)=i;
th_2(i)= theta_2(i)*pi/180; % theta 2 in radians
% using equation from book to calulate the postion of the links
% position of link 2 (AO2)
A_X(i) = R2*cos(th_2(i)); % position x of link 2
A_Y(i) = R2*sin(th_2(i)); % position y of link 2
end
i have so much more to put in this for loop and i don't want to get that warrning

Respuestas (1)

David Hill
David Hill el 30 de Mzo. de 2020
No for-loop needed. No preallocation needed here.
theta_2=1:360;
th_2=theta_2*pi/180;%you could use cosd() and not need to convert
A_X=R2*cos(th_2);
A_y=R2*sin(th_2);
  1 comentario
Shaghayegh Ghandali
Shaghayegh Ghandali el 30 de Mzo. de 2020
omg i never though about that thank you

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by