MATLAB: Print a circular disk onto the graph

circlediscfigurefilled circleplot

Hi! I now work in a project to simulate the solarsystem on a very simple level. The assingment is to plot the path of orbit of the planets and to plot a sketched sun in the center. It feels like a simple thing but i cant manage to figure out how to do it. are there any comands that can plot circles or discs? it should symbolize the sun so it has to be filled. Any suggestions?
Im looking forward for answers.
Kind regards, Viktor

Best Answer

Ironically, you can use the rectangle() function with 100% curvature to plot a circle.
The position property specifies the lower, left corner of the rectangle, not the center of it, along with the width and height (in this case, diameter). So if you'd like your circle centered at (0,0) with a diameter of 10, you'll need to subtract 10/2 from (0,0) in order to specify the lower, left "corner" of the rectangle.
Be sure to set axes to 'equal' so the aspect ratio depicts a circle.
center = [0,0];
diameter = 10;
figure
h = rectangle('Position',[center-diameter/2, diameter, diameter],'Curvature',[1,1], 'FaceColor', 'y', 'EdgeColor', 'k');
axis equal