Drawing a circle .. help please.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Keith Elliott
am 13 Jun. 2018
Kommentiert: Keith Elliott
am 14 Jun. 2018
Hi .. I'm trialling matlab to see if it's worth the money for me. Array limits, speed and graphical output being my concerns.
right now I can't even draw a circle and would appreciate any advice.
the first code I tried was
clear
x=-1:0.01:1;
y=sqrt(1-(x.^2));
y1=-y;
plot(x,y)
plot(x,y1)
This only gives me half a circle(upper or lower).
Also if I use 0.0000001 as the steps instead of 0.01 the calculations are quick but the plot takes forever to happen.
I then tried ..
clear
x=-1;
while(x<1)
y=sqrt(1-(x^2));
plot(x,y)
x=x+0.01;
end
to try and avoid array size issues and plot points as you calculate them (without storing data) but this didn't give me any chart at all (heaven knows why not)
any suggestions / clarifications very welcome
thanks
0 Kommentare
Akzeptierte Antwort
Aquatris
am 13 Jun. 2018
Bearbeitet: Aquatris
am 13 Jun. 2018
Use a different equation that describes the circle to make it easier.
theta = 0:0.01:2*pi;
r = 2;
x = r*cos(theta);
y = r*sin(theta);
plot(x,y),axis equal
The problem with your approach is, plot function overwrites the data. Use
plot(x,y,x,y1)
or if you want both parts to be the same color use
plot(x,y,'b',x,y1,'b')
where 'b' stands for blue.
Alternatively, after the first call to plot function, add 'hold on' to tell Matlab the next plot function should not erase the previous content within the plot.
Weitere Antworten (2)
Image Analyst
am 13 Jun. 2018
Code samples for drawing circles, ellipses, and arcs are in the FAQ: https://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
Keith Elliott
am 13 Jun. 2018
2 Kommentare
Image Analyst
am 13 Jun. 2018
His code is basically the 5th code chunk in the FAQ I gave you the link for.
Siehe auch
Kategorien
Mehr zu Logical 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!