How to remove for loops from this code
이전 댓글 표시
r=0.5:0.5:4 ;
theta=0: (pi)/4 : 7*(pi)/4 ;
[X,Y] = meshgrid(r, theta);
polar=zeros(64, 2);
for j=1:8
for i=1:8
polar((8*(i-1)) + j, 1)= X(j,i);
polar((8*(i-1)) + j, 2)= Y(j,i);
end
end
cart=zeros(64, 2);
for i=1:64
cart(i, 1)= polar(i,1) * cos(polar(i,2));
cart(i, 2)= polar(i,1) * sin(polar(i,2));
end
cart
Im getting the correct awnser but I need to remove the for loops from it any advice is welcome.
답변 (1개)
Star Strider
2019년 2월 5일
I’m not certain what you want to do, although my best guess is that you want to convert your polar coordinates to Cartesian.
Try this:
r=0.5:0.5:4 ;
theta=0: (pi)/4 : 7*(pi)/4 ;
[R,Th] = meshgrid(r, theta);
[X,Y] = pol2cart(Th,R);
figure
plot(X,Y)
axis equal
Experiment to get the result you want.
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!