Code covered by the BSD License  

Highlights from
Graphical data selection tool

4.95833

5.0 | 24 ratings Rate this file 116 Downloads (last 30 days) File Size: 10.2 KB File ID: #13857
image thumbnail

Graphical data selection tool

by

 

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
Description

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.

plot(rand(5,2),rand(5,2),'o')
[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.

plot(rand(5,2),rand(5,2),'o')
[pind,xs,ys] = selectdata('sel','br','action','delete')
pind =
    [3]
    [4]
xs =
    [0.67745]
    [0.69115]
ys =
    [0.76837]
    [0.59464]

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 =
    20
    78
    99
xs =
         0.19
         0.77
         0.98
ys =
       2.3639
       3.2279
       3.7707

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.

Acknowledgements

This file inspired Telo Tool Terminal Restriction Fragment Analysis, Ginput2.M V3.1 (Nov 2009), and Dtmcursor.

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 (27)
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

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

24 Mar 2013 Ricardo Portal

Very helpful. Thanks

21 Mar 2013 arnold

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

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

27 Feb 2010 John D'Errico

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.

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?

09 Oct 2009 M

N-I-C-E.
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  
01 Mar 2009 Joshua  
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
fighandle=ancestor(params.Axes,'figure');
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);

To:

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

Thanks

11 Sep 2007 F Moisy

just perfect

07 May 2007 Marcel Bison

Amazing job !!
Very usefull file
Thanks

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.

Updates
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