Lozansky
Lozansky

Reputation: 374

Function that returns colored circle in Matlab

I want to define a function that returns a circle with a given radius, center and filled color. My function now only returns a circle with a given radius and center but I do not know how to implement a variable that fills the circle with any given color. Here is the function code for the circle as is:

function h = circle(x,y,r)
hold on
th = 0:pi/100:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h=plot(xunit,yunit)
hold off

I think I need to change h=plot... to h=fill(xunit,yunit,'color') but I do not understand how. Any advice?

Upvotes: 0

Views: 112

Answers (1)

Zoltan Csati
Zoltan Csati

Reputation: 699

Just do what you wrote. E.g.

h = fill(xunit, yunit, 'red');

It handles your circle as a polygon and fills it with red.

Upvotes: 2

Related Questions