# plotting circles

533 vues (au cours des 30 derniers jours)
Yasmin Tamimi le 12 Mar 2011
Commenté : Michelle Hirsch le 11 Déc 2023
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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
fatima ibrahim le 29 Fév 2020
function draw_circle1(x,y,R,c)
t =0:0.05:6.28;
x1 = (x +R*cos(t))';
y1= (x +R*sin(t))';

Connectez-vous pour commenter.

### Réponse acceptée

Paulo Silva le 12 Mar 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 commentairesAfficher 6 commentaires plus anciensMasquer 6 commentaires plus anciens
Rik le 3 Mai 2020
It's the step size. You can use the colon in two ways when you create an array:
start:stop
start:step:stop
Özgür Saglam le 3 Mai 2020
Thank you very much!

Connectez-vous pour commenter.

### Plus de réponses (3)

Michelle Hirsch le 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
##### 5 commentairesAfficher 3 commentaires plus anciensMasquer 3 commentaires plus anciens
Royi Avital le 10 Déc 2023
@Michelle Hirsch, It would be great if it had the DisplayName property like most other objects.
It makes easier when adding it to the legend.
Michelle Hirsch le 11 Déc 2023
@Royi Avital I think it's more than just adding DisplayName - annotations like rectangle (intentionally) don't show up in legend since they are meant to be annotations, not data. Are you interested in being able to include annotations in legend? If so, please share more about your use case so I make sure we understand what you are thinking.

Connectez-vous pour commenter.

Chad Greene le 21 Août 2014
This'll do the job.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Image Analyst le 20 Jan 2016
Modifié(e) : Image Analyst le 15 Avr 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 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by