Plot Circle in MATLAB

This tutorial will discuss plotting a circle using the rectangle() function in Matlab.

Plotting a Circle Using the rectangle() Function in MATLAB

We can use the rectangle() function to plot a circle in Matlab. We have to pass the position using the Position property and set the curvature to 1 using the Curvature property inside the rectangle() function. For example, let’s plot a circle using the rectangle() function. See the code below.

clc
position = [2 4 2 2]; 
rectangle('Position',position,'Curvature',[1 1])
axis equal

Output:

plotting circle using the rectangle function

The position vector contains four values. The first value is the x coordinate. Meanwhile, the second value is the y coordinate. The third value is the width of the circle, and the fourth value is the height of the circle. The width and height values should be equal to plot the circle. We can also change other properties of the circle like the width of the line using the LineWidth property, the line style using the LineStyle property, the face color or the fill color using the FaceColor property, and the edge color or the color of the line using the EdgeColor property. The line width should be a positive numeric value. We can add any color as face and edge color. The supported line styles are dashed, dash-dotted, dotted, and none. For example, let’s change the line width of the above circle to 5, the face color to yellow, the edge color to red, and the line style to dash-dotted. See the code below.

clc
position = [2 4 2 2]; 
rectangle('Position',position,'Curvature',[1 1],'FaceColor','yellow','EdgeColor','red','LineWidth',5,'LineStyle','-.')
axis equal

Output:

changing circle properties

In the output, the properties of the circle have been changed.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - MATLAB Plot

  • Change Legend Title in MATLAB