MATLAB Answers

0

plotting circles

Asked by Yasmine Tamimi on 12 Mar 2011
Latest activity Commented on by Image Analyst
on 14 Apr 2016

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.

  0 Comments

5 Answers

Paulo Silva
Answer by Paulo Silva
on 12 Mar 2011
 Accepted answer

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

before the circles being added.

  1 Comment

Firas
on 29 Dec 2014

That's awesome


Answer by Michelle Hirsch
on 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 Comments

Image Analyst
on 29 Jan 2016

And with R2012a and later you can use viscircles

Thanks very much Michelle. Your idea made beautiful concentric circles. viscircles didn't work on my computer because I have version R2011a.

Image Analyst
on 14 Apr 2016

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.


Image Analyst
Answer by Image Analyst
on 5 Jul 2012

  0 Comments


Answer by Chad Greene
on 21 Aug 2014

This'll do the job.

  0 Comments


Answer by Image Analyst
on 20 Jan 2016

  0 Comments


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!