consider preallocating for speed
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
David Hill
2020-3-30
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);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!