How to plot a Circle in Matlab

6
How to draw a Circle in Matlab This also works in GNU-Octave, FreeMat, Scilab and Scicoslab

description

How to plot a circle in Matlab using simple parametric equations. This is accomplished in 5 easy steps. For more information, visit: http://matrixlab-examples.com/matlab-plot.html 1.- Define the initial and final angles to be considered, and a step for each point. 2.- Define your x-values, along the horizontal axis. That's cos(angles). 3.- Create your y-values, along the vertical axis. That's sin(angles). 4.- Your parametric curve will use the cosine and the sine of the angles, just plot that. 5.- For visualization, force your x-distance to equal your y-distance on the plot, with axis('equal'). Done!

Transcript of How to plot a Circle in Matlab

Page 1: How to plot a Circle in Matlab

How to draw a Circle in Matlab

This also works in GNU-Octave,

FreeMat, Scilab and Scicoslab

Page 2: How to plot a Circle in Matlab

We’re going to use paremetric equations to

describe a circumference in 5 easy steps.

1st. Step: define the values of the angles to

be considered.

angle = linespace(0, 2*pi, 360);

this defines 360 values from 0 to 2π radians.

Page 3: How to plot a Circle in Matlab

2nd. Step: calculate the horizontal values of

your points:

x = cos(angle);

3rd. Step: calculate the vertical values of

your points:

y = sin(angle);

Page 4: How to plot a Circle in Matlab

4th. Step: plot your 360 pairs of x and y

values:

plot(x, y)

5th. Step: force your x distance to equal

your y-distance in the plot:

axis('equal')

Page 5: How to plot a Circle in Matlab

So this short code:

angle = linspace(0, 2*pi, 360);

x = cos(angle);

y = sin(angle);

plot(x, y)

axis('equal')

Produces this plot:

Page 6: How to plot a Circle in Matlab

For more examples and details, visit:

matrixlab-examples.com/matlab-plot.html