Hello, I have a problem with for loops and plotting the lines.
조회 수: 3 (최근 30일)
이전 댓글 표시
Good afternoon colleques,
I have a question, I need to plot 181 lines from +90° to -90° using for loop. I have tried this (but it seems to be wrong):
for i=0:1:181 angle=i; for k=1:200
x2(k)=k*cos(angle);
x1(k)=0;
y1(k)=0;
y2(k)=k*sin(angle);
plot(x1,y1,x2,y2)
end
end
As a results it plots only one line, instead of 181 on different angles.
Looking forward to your answers and suggestions and thank you in advance.
댓글 수: 0
답변 (1개)
Naga
2024년 10월 23일
Hello Daniil,
To plot 181 lines from +90° to -90° using a for loop, you can use the following code. It calculates the starting and ending points of each line based on the angles, then plots them on the same graph. The hold on command ensures all lines are displayed together. Here’s the code:
angles = 90:-1:-90;
linecoord = [0, 1];
for angle = angles
x = cosd(angle) * linecoord;
y = sind(angle) * linecoord;
plot(x, y);
hold on;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!