필터 지우기
필터 지우기

consider preallocating for speed

조회 수: 1 (최근 30일)
Shaghayegh Ghandali
Shaghayegh Ghandali 2020년 3월 30일
댓글: Shaghayegh Ghandali 2020년 3월 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

답변 (1개)

David Hill
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);
  댓글 수: 1
Shaghayegh Ghandali
Shaghayegh Ghandali 2020년 3월 30일
omg i never though about that thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by