File Exchange

image thumbnail

Graphical data selection tool

version 1.0 (10.2 KB) by

A graphical tool to modify your plots and locate data points

36 Ratings



View License

Editor's Note: This file was a File Exchange Pick of the Week

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.

Comments and Ratings (43)

Ferit Akgul

Superb tool!

Really Usefull

Found this useful, but didn't realise at first mouse button must be held down when using brush setting. Still saved me a lot of time, thanks for putting this up.

nice work but...could please provide a version that works with gscatter and scatter ?

It would be very useful :)

Thanks !

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.


Tyler (view profile)

Vikram Goel

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');


Joseph (view profile)

Any wa to make multiple selections?


A wonderful tool, and nicely coded!

Thanks a LOT

Emily Toomey

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

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?

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?


Pietro (view profile)

Orly amsalem

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.


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');

Very helpful. Thanks


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?



ori (view profile)

nice tool...



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.

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.

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?


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".


Arthur (view profile)


Joshua (view profile)

Cheng-ta Yang

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.

adhi dm

two thumbs up!!

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.

G Coppola

Exactly what I needed


F Moisy

just perfect

Marcel Bison

Amazing job !!
Very usefull file

JJ nigaud

this script rocks... hail!!!

Zhijun Wang

Excellent work and very useful file!

jun ziyang

Great work!

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.


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.

MATLAB Release
MATLAB 7.3 (R2006b)
Tags Add Tags

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

» Watch video