File Exchange

image thumbnail


version (4.38 KB) by Rajiv Narayan
An interactive ellipse selection tool


Updated 09 Oct 2006

View License

ELLIPSESELECT An interactive ellipse selection tool

Creates the ellipse and initialzes callbacks. Returns the handle of the ellipse HE.
Ellipse parameters:
A Length of the semi-major axis
B Length of the semi-minor axis
X0 Abscissa of the center of the ellipse
Y0 Ordinate of the center of the ellipse
PHI Angle (in radians) between x-axis and the major axis
STYLE Definition of the plotted line style
Once created, the ellipse shape can the adjusted interactively using the mouse.
The center can be moved by dragging the 'x' at the center of the ellipse. The lengths of the axes can be adjusted by dragging on the red and black control points on the ellipse. The ellipse can be rotated through an arbitrary angle by left clicking and dragging on the ellipse boundary.
The ellipse parameters are saved in the ellipse handle's userdata roperty and can be obtained using:
PARAMS = ELLIPSESELECT('params', HE), where PARAMS is a structure with the ellipse parameters.
The ellipse can be deleted by right clicking on the ellipse boundary and selecting 'delete' from the context-menu. Alternatively, the ellipse can be deleted programmatically by using the following call to ELLIPSESELECT.
STATUS returns 0 if the delete operation was successful, -1 otherwise.

%generate some data
phi=pi/4; rotmat = [cos(phi),sin(phi);-sin(phi),cos(phi)];
scatter(y(1,:),y(2,:),'c.'); hold on
%create an ellipse
he = ellipseselect('init',1,1,0,0,pi/4,'r-.');
% modify ellipse line style
% get current ellipse parameters
params = ellipseselect('params',he);
% delete the ellipse
status = ellipseselect('deletehandle',he);

Cite As

Rajiv Narayan (2021). Ellipseselect (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)


FYI, the easiest solution for Matlab version > R2014a is to change line 302 of ellipseselect.m from "num2str(hnd)" to "double(hnd)". However, this solution may break in future releases.

Erika Fong

What did you change the line num2str(hnd) to?

sukesh adiga

Conversion of handle to string is wrong.
Changing this line num2str(hnd) worked for me.
This is nice piece of work.

Ryan Stafford

This worked great in older versions of Matlab, but is now throwing errors for r2015 due to "upgraded" graphics...

Any tips to resolve this issue?

Undefined function 'abs' for input arguments of type ''.

Error in num2str (line 66)
xmax = double(max(abs(widthCopy(:))));

Error in ellipseselect>cbkstr (line 301)
s=sprintf ('cbkswitch(''%s'' , ''%s'', %s)',mfilename, action, num2str(hnd));

Error in ellipseselect (line 87)
cbk=cbkstr(he, 'down');

Mech Princess

The coolest & useful program ever. To edit the ellipse in real time, you should unselect the arrow on top (took a while to figure it out)

Anathea Pepperl

This code was very helpful and easy to use.

Tripti Bhaskaran

I found this code very useful and well documented.

MATLAB Release Compatibility
Created with R13SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: EllipseDraw1.0

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!