Asked by MathWorks Support Team
on 26 Jul 2010

I would like to plot a circle with a given radius and center.

Answer by MathWorks Support Team
on 3 Jan 2019

Accepted Answer

Here is a MATLAB function that plots a circle with radius 'r' and locates the center at the coordinates 'x' and 'y':

function h = circle(x,y,r)

hold on

th = 0:pi/50:2*pi;

xunit = r * cos(th) + x;

yunit = r * sin(th) + y;

h = plot(xunit, yunit);

hold off

An alternative method is to use the 'rectangle' function:

function h = circle2(x,y,r)

d = r*2;

px = x-r;

py = y-r;

h = rectangle('Position',[px py d d],'Curvature',[1,1]);

daspect([1,1,1])

If you are using version R2012a or later and have Image Processing Toolbox, then you can use the 'viscircles' function to draw circles:

viscircles(centers,radii)

Answer by serwan Bamerni
on 17 Feb 2016

There is now a function called viscircles():

Walter Roberson
on 17 Oct 2016

This is part of the Image Processing Toolbox

ceethal piyus
on 16 May 2019

I've applied circular hough tranform for identifing the circlular objects in an image and i got the results . But when i used the code into an app designer, insted of ploting the circles into the image where the centers are marked its ploting the circle in a different figure. How can i get both circles and center points into the same axes ( named "app.segmented" )

error

How to add the axes name to viscircles function in an app designer. I tired

viscircles(centres,radii,'color','b','parent','app.segemented'); which is giving the following error.

Sign in to comment.

Answer by amine bouabid
on 23 Jul 2018

Edited by amine bouabid
on 23 Jul 2018

hello

you can plot a circle simply by writing :

syms x; syms y;

ezplot((x-xi).^2+(y-yi).^2-r.^2)

where xi and yi are the coordinates of the center and r is the radius

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Manar Mahmoud (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_258691

## Christoph (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_260374

## Walter Roberson (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_388817

## bushra mughal (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_401575

## Walter Roberson (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_401589

## Chinthamakula Saikiran (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_471988

## Michael Abboud (view profile)

Direct link to this comment:https://kr.mathworks.com/matlabcentral/answers/98665-how-do-i-plot-a-circle-with-a-given-radius-and-center#comment_473774

Sign in to comment.