Filter löschen
Filter löschen

Hello, I have a problem with for loops and plotting the lines.

1 Ansicht (letzte 30 Tage)
Daniil Rulev
Daniil Rulev am 27 Jan. 2016
Beantwortet: Amith am 1 Mär. 2023
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.

Antworten (1)

Amith
Amith am 1 Mär. 2023
As per my understanding you wanted to know how to plot 181 lines from +90 to -90 using for loop. Here is a code demonstration to do the same .The angles represent the starting and the ending angles in an array and linecoord represents the starting and ending coordinates of the lines you can adjust it accordingly. In the for loop I have just multiplied the sin and cos angles in degrees to the line coordinates for every angle and have plotted it on the same graph using hold on.
Here is the code for the same,
angles = 90:-1:-90;
linecoord = [0,1];
for angle = angles
x = cosd(angle)*linecoord;
y = sind(angle)*linecoord;
plot(x,y);
hold on;
end

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by