View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Graphical data selection tool

5.0 | 33 ratings Rate this file 70 Downloads (last 30 days) File Size: 10.2 KB File ID: #13857 Version: 1.0
image thumbnail

Graphical data selection tool


John D'Errico (view profile)


05 Feb 2007 (Updated )

A graphical tool to modify your plots and locate data points

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

Selectdata is a tool that allows the user to graphically select one or more points from a 2-d plot using a variety of graphical tools. You can specify a lasso tool, a paint brush of two shapes and various sizes, an expanding rectangle, or just click near a desired point.

As points are selected with the tool of choice, they become highlighted (temporarily) until the mouse button is released. Then the index of the points selected, plus their (x,y) coordinates are returned. The user has control of many aspects of the tool, including whether the selected points are to be deleted from the plot. (There are also some hidden options that I did not include in the help itself. You can find them by editing the file.)

I wrote this tool as a generic utility one could call from within a gui based modeling application. It could also be useful when called directly from the commandline to identify data points or sets of points on a plot, or to delete points (outliers) from a plot. It can be used to return the points selected or all of those that remained unselected. In my own use of this tool, I use it to identify sets of points for which I wish to modify the regression weights.

Some examples of use:

Simple selection with a lasso - I selected one point from one of the two curves, and two points from the second curve.

[pind,xs,ys] = selectdata('selectionmode','lasso')
pind =
    [ 3]
    [2x1 double]
xs =
    [ 0.099422]
    [2x1 double]
ys =
    [ 0.87571]
    [2x1 double]

Selection with a circular brush, deleting those selected from the plot.

[pind,xs,ys] = selectdata('sel','br','action','delete')
pind =
xs =
ys =

Plot two curves, one is data, the second a model. Allow the selection tool (the lasso) to only see the data.

x = 0:.01:1;
y = exp(x);
ydata = y + randn(size(y))/2;

h1 = plot(x,y,'r-');
hold on
h2 = plot(x,ydata,'o');
[pind,xs,ys] = selectdata('sel','lasso','ignore',h1)

pind =
xs =
ys =

Thanks to Jiro and a reviewer for some great ideas for the enhancements implemented in version 2.

Version 3 has the ability to label each selected point with its coordinates.

Please send me e-mail if you find any problems.


This file inspired Telo Tool Terminal Restriction Fragment Analysis, Drag Line With Callback, Ginput2.M V3.1 (Nov 2009), Dtmcursor, and T Marigram.M V1.3.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements I originally wrote this in release 14 SP1, so it should work at least that far back. It uses nested functions for the callbacks, so R14 may be the limit.
Tags for This File   Please login to tag files.

No tags are associated with this file.

Please login to add a comment or rating.
Comments and Ratings (39)
19 Jan 2017 Tarkes Dora

I was trying this on saved Scatter figure file. I am unable to apply this on a scatter plot.One would be interested in selecting points from a scattered cloud of points. Such tools has most important application in these kind of problems.

Comment only
18 Dec 2016 Tyler

Tyler (view profile)

08 Nov 2016 Vikram Goel

31 Oct 2016 Jeremias Sibold

A wonderful tool.

if you have a Text field in your data plot than this tool crashes.

to fix this you should only get the xdata and ydata from graphic types of 'line'.

So to fix this you should implement this short code at line 314

% strip out xdata and ydata of lines
Types=get(hc, 'Type');
for k=1:numel(Types)
if strcmp(Types{k},'line')
xdata = get(hc(find(Linetypes)),'xdata');
ydata = get(hc(find(Linetypes),'ydata');

Comment only
19 Sep 2016 Joseph

Joseph (view profile)

Any wa to make multiple selections?

07 Sep 2016 Aurelien

A wonderful tool, and nicely coded!

20 Jun 2016 Ghassan Falouji

Thanks a LOT

10 Jun 2016 Emily Toomey

Fantastic tool! So helpful and easy to use. Exactly what I've been looking for.

07 Jan 2016 Fabricio Fernandez

01 Jul 2015 Anders Almholt

Great Tool.

I would like to implement the selection tool in a GUI. But I get an error message that the figure handle is in use by another object.

Any ideas?

07 May 2015 Architha Kommera

Hi, this tool is very helpful but this cant work on 3D plots. I'm looking for the exact same thing for 3D plots. can somebody suggest relevant function?

Comment only
03 Nov 2014 Pietro

Pietro (view profile)

14 Mar 2014 Orly amsalem

21 Jan 2014 Mark S.

Really a great function. I cannot believe that Matlab did not already include this,especially since the curvefit GUI basically has this sort of thing built in. It saved me tons of time.

16 Sep 2013 Renee

Renee (view profile)

Easy to use.

suggestion: add ability to choose multiple single points but easy enough to code as a while loop, e.g.:
% initialize selection variables
i = 0;
choose = 'y';

while strmatch('y', choose)
i = i + 1; % increment peak count
[j, x(i), y(i)] = selectData('selectionmode', 'closest'); % user script
choose = input([num2str(i) ' peaks chosen -- choose another? (y or n) '], 's');

24 Mar 2013 Ricardo Portal

Very helpful. Thanks

21 Mar 2013 arnold

arnold (view profile)

Great function, I wish it worked with images though. Been looking for a function that provides me with a way to select a certain image area and it gives me the list of indices.

Is there a way to do this with your selection tool?

28 Jan 2013 Sergey Kucheryavskiy

22 Oct 2012 Giacomo

26 Jul 2012 ori

ori (view profile)

nice tool...

09 May 2011 Christine

21 Mar 2011 salamay

27 Feb 2010 Ramiro Massol

hi John, it would be nice to add some 'disable' functionality to your selectdata function. By this I mean the ability to launch selectdata under control of a togglebutton (similar to the brush togglebutton), so if the user wants to cancel selection he can also toggle off the controller.
ps: by the way, there's a minor bug in the 'axes' property. If you have more than 1 axes in the figure and the user tries to select something from the wrong axes (i tried so far 'rect' as a tool) selectdata allows other axes to be used for selection though the selection tools does not work properly.

Comment only
27 Feb 2010 John D'Errico

John D'Errico (view profile)

Hmm. Having just now installed R2010a, I'll do my best to make it compliant immediately. This code has always been slightly sensitive, so I'm not surprised if a newer release might have caused problems.

Comment only
26 Feb 2010 Ramiro Massol

this function does not work in Matlab 2009a. I always get the following error:

??? Error using ==> get
Invalid property found.
Object Name : text
Property Name : 'xdata'.
Error in ==> selectdata at 315
xdata = get(hc,'xdata');

any clues?

Comment only
09 Oct 2009 M

M (view profile)

I cannot understand why something similar is not implemented in matlab yet.
It would be nice if one could add several selections by pressing e. g. "Ctrl".

01 Apr 2009 Arthur

Arthur (view profile)

01 Mar 2009 Joshua

Joshua (view profile)

16 Oct 2008 Cheng-ta Yang

08 Jul 2008 Malcolm Lidierth

Simple-to-use and attractive tool.
One trivial suggestion:
Line 198
fighandle = get(params.Axes,'parent');
can be replaced with
which extends selectdata's use to axes parented by e.g. a uipanel.

24 Jan 2008 adhi dm

two thumbs up!!

15 Jan 2008 Stefan Novak

Just what I was looking for!

One adjustment had to be made. Lines 645-646 had to be changed from:

xselect = xdata(pointslist);
yselect = ydata(pointslist);


xselect = xdata(pointslist<=size(xdata,1));
yselect = ydata(pointslist<=size(ydata,1));

Otherwise elements in pointslist was trying to call on elements outside of the range of x/y data.

Hope this helps.

23 Nov 2007 G Coppola

Exactly what I needed


11 Sep 2007 F Moisy

just perfect

07 May 2007 Marcel Bison

Amazing job !!
Very usefull file

07 Mar 2007 JJ nigaud

this script rocks... hail!!!

06 Feb 2007 Zhijun Wang

Excellent work and very useful file!

06 Feb 2007 jun ziyang

Great work!

06 Feb 2007 nice job

Interesting tool! It seems that if one is not satistified with current selection, the user has to re-run the command. It would be more handy if the user can keep trying until s/he satisfy the results.

07 Feb 2007

Version 2 - Add new options - verification by request, plus allow the return of all points NOT selected instead. Also documentation enhancements. Made the single point selector use Euclidean distance in the plot window units. Also fixed a minor bug.

Contact us