# plotting circles

999 Ansichten (letzte 30 Tage)
Yasmin Tamimi am 12 Mär. 2011
Bearbeitet: Image Analyst am 15 Apr. 2022
How can I plot circles, same radius and different centers, all in one graph. I used the following command to draw +,o,diamond: plot (x,y,'ro',u,v,'gd',A,B,'b+'); where x,y,u,v,A,B are all row vectors. And I want to add circles to that plot where the o will be the center.
##### 1 KommentarKeine anzeigenKeine ausblenden
fatima ibrahim am 29 Feb. 2020
function draw_circle1(x,y,R,c)
t =0:0.05:6.28;
x1 = (x +R*cos(t))';
y1= (x +R*sin(t))';

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Paulo Silva am 12 Mär. 2011
Here's a function to draw circles:
function circle(x,y,r)
%x and y are the coordinates of the center of the circle
%r is the radius of the circle
%0.01 is the angle step, bigger values will draw the circle faster but
%you might notice imperfections (not very smooth)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(x+xp,y+yp);
end
If you want to add circles you must insert the command
hold on
##### 8 Kommentare7 ältere Kommentare anzeigen7 ältere Kommentare ausblenden
Özgür Saglam am 3 Mai 2020
Thank you very much!

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (3)

Michelle Hirsch am 29 Jan. 2016
It's counter-intuitive, but this is actually really easy with the rectangle function. From the rectangle documentation :
pos = [2 4 2 2];
rectangle('Position',pos,'Curvature',[1 1])
axis equal
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Image Analyst am 14 Apr. 2016
Bearbeitet: Image Analyst am 15 Apr. 2022
rectangle() is one of several methods listed in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F> You'll have lots of other nice improvements that they've made over the last 5 years if you upgrade.
numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
grid on;
axis equal

Melden Sie sich an, um zu kommentieren.

Chad Greene am 21 Aug. 2014
This'll do the job.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Image Analyst am 20 Jan. 2016
Bearbeitet: Image Analyst am 15 Apr. 2022
numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
grid on;
axis equal
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Graphics Performance in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by