Selecting data from a plot in a GUI

I have a plot on my GUI and I want to select some points on this plot and save their coordinates to a variable. The variable would have rows containing each point and 2 columns for the x,y values for those points.
I have tried using the brush function to select the data and then save it to a variable, but that is giving me problems.
Any other ideas?
Thanks!

Antworten (3)

Fangjun Jiang
Fangjun Jiang am 12 Jul. 2011

6 Stimmen

plot(magic(5));
[x,y]=ginput
You can select multiple data points, Press return when you are done.

3 Kommentare

Michael
Michael am 12 Jul. 2011
What if I want to select multiple points at once. I have hundereds of points and I want to select a group of them with a selection box. Is there a similar function for that?
Fangjun Jiang
Fangjun Jiang am 12 Jul. 2011
I am not aware of any function for that. You could develop some code to do that since you have the original data for the curve. For example, use [x,y]=ginput(2) to get two data points, then you can select all the data points that is fallen between x(1)<x<x(2) and y(1)<y<y(2).
Michael
Michael am 12 Jul. 2011
That worked great. Thanks so much!

Melden Sie sich an, um zu kommentieren.

Fangjun Jiang
Fangjun Jiang am 13 Jul. 2011

3 Stimmen

Michael, I've been thinking about this problem. You can use Brush on your plot. Click the "Brush" icon, select a group of data points, then select the highlighted data point and right click, you can select "Create Variable" which then will ask you for a variable name. Or, you can select "Copy Data to Clipboard", then in the Command window, you can type MyData=clipboard('paste'). Does this satisfy your need, or you need more formal API to use the Brush functionality? There is a lead in this post but I have not found an API for Brush yet.
Andy
Andy am 28 Jan. 2015

0 Stimmen

An excellent option is provided below:
hBrushLine = findall(gca,'tag','Brushing');
brushedData = get(hBrushLine, {'Xdata','Ydata'});
brushedIdx = ~isnan(brushedData{1});
brushedXData = brushedData{1}(brushedIdx);
brushedYData = brushedData{2}(brushedIdx);
% and similarly for ZData in 3D plots

Gefragt:

am 12 Jul. 2011

Beantwortet:

am 28 Jan. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by