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')
Selection with a circular brush, deleting those selected from the plot.
[pind,xs,ys] = selectdata('sel','br','action','delete')
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-');
h2 = plot(x,ydata,'o');
[pind,xs,ys] = selectdata('sel','lasso','ignore',h1)
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.
Hi! Can it work for a 3d scatter plot? If you can add that functionality, it will be great
Wonderful work on both the documentation and the flexibility provided via the extensive varargin list. The design style of this code should be used as a standard for coders to follow!
Have you figured out how to implement it on guide?
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 :)
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.
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
xdata = get(hc(find(Linetypes)),'xdata');
ydata = get(hc(find(Linetypes),'ydata');
Any wa to make multiple selections?
A wonderful tool, and nicely coded!
Thanks a LOT
Fantastic tool! So helpful and easy to use. Exactly what I've been looking for.
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.
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?
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.
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
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?
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.
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.
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');
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".
Simple-to-use and attractive tool.
One trivial suggestion:
fighandle = get(params.Axes,'parent');
can be replaced with
which extends selectdata's use to axes parented by e.g. a uipanel.
two thumbs up!!
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.
Exactly what I needed
Amazing job !!
Very usefull file
this script rocks... hail!!!
Excellent work and very useful file!
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.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.