File Exchange

image thumbnail


version (2.31 KB) by David Long
Adds ellipses to the current plot


Updated 26 Mar 2018

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Adds ellipses to the current plot

Cite As

David Long (2020). ellipse.m (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (69)



I find this ellipse.m by Andrew Schwartz to be more natural to use and a few more features:

Mohib Ullah

Very useful code. However, I had some problem with the orientation. By subtracting the angle from pi fixed my problem.

David Long

usage notes have been corrected to address sis when's comment

sisi chen

I think there is something wrong with the math here. If you run the example code: ellipse(1,2,pi/8,1,1,'r'), you get an ellipse tilted downwards at 45 degrees, not upward. Also pi/8 should be 22.5 degrees, not 45 degrees.

Asad Ali


very helpful. thank you.

can someone please explain difference between ra, rb and ang in it?

Hi David Long, is there any possibility to get a point on the ellipse that we get from your program

light liu

very useful,thanks


Hi David, Thank you - I assumed as much but thought I ought to check! Thanks.

David Long

There is a typo in the comments section. ra is the semimajor axis, rb is the semimionr axis (ra>=rb), and ang is the angle of the semimajor axis.


Could anyone clarify for me the difference between ra and rb please? The function states that "% ELLIPSE(ra,rb,ang,x0,y0) adds an ellipse with semimajor axis of ra,
% a semimajor axis of radius rb, a semimajor axis of ang, centered at
% the point x0,y0."
I assume that one or the other should be semiminor axis?

David Long

Using the pointer output ellipse as suggested in the previous comment, you can change the C argument to the standard patch command to use a vector (RGB) color. patch has some other interesting options you can use, too.


If instead of filling the ellipse with a specific color, would it be possible to fill it according to a vector?
How could that be done?

ramin bba

thanks. With a minor change it worked. the outputs (x, y) are cells so using patch gave me an error. I put your code in a for loop to get around the problem:

for i=1:length(x)
hold on;
hold off;

David Long

To efficiently produce a "filled" ellipse using this code, use the returned handle:
hold on;
hold off;

ramin bba

awesome code, helped me out a lot.

Do you have an efficient way in mind for "filling in" the ellipses? using patch maybe?



quite useful

David Long

R2014B graphics ready


Jay Patel



excellent! helped me a lot thank you

Yuri K

Congratulations for getting PoW! Great tool!



very good, very appreciate

Works Great,
Thanks for sharing...

Ben Bauer

piao lin


excellent work, useful and well documented¡¡¡

Chen Xing

Many thanks!! Quick and simple

Bharat Pathak

Thank you very much.

Tory C

Great! Thank you! Is there a quick way to make the line thickness bigger?? Cant find the obvious fix in the code.



so cool!

thanks a lot

julio gomez

Fabiano Giuliani

A perfect function to draw an ellipse. Thank you!

Natt T


MARGOT Gerritsen

Works like a treat

Y Liu

Andrzej Z

Reza Zahiri

nice and clean piece of code, thanks for sharing

kim jeongdae


peppo franco

jung sung yun

Yassir Al-Jahdir

Thank you very much!!

Kazimieras Bagdonas

thanx, yours function saved my day=)

Sanith Wijesinghe


Stephen Westland

Saved my bacon today. Perfect.

Omar Muhanna

thank you very much for this file. because I was looking for such a function in MatLab that can draw for me an ellipse.but if you can send me the simpleat function for drawing such a simple ellipse I will be very greatful.

thank you...

Richard Weaver

Excellent- just what I needed - allows full user specification of the ellipse parameters.

peter YOU


P Sirisalee

Many Thanks.

Paul Larsen

Works great! Thanks a million.

Yuval Tassa

Watch out for the missing semicolon in line 131. Otherwise, a great little util.

Gregory B

Thanks a lot!

Tom Thorvaldsen

Made my life much easier.

Mark Wilde

i like a lot. makes me happier than the other 2 guys could ever be!

ke wang

It helps me a lot! Thank you very much

L. O'Neill

This function is easy to use, logical, and does exactly what it says it will. I am very happy with it.


updated and corrected usage notes in documentation
set so that handles to ellipses are only returned when an output is specified

MATLAB Release Compatibility
Created with R10
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags