How can I infer from the data cursor position, the index of the closest datapoint
5 ビュー (過去 30 日間)
I am working in the App Designer and I want to have a tool which lets the user select a bunch of datapoints. I have a UI Axes and defined a ButtonDownFcn.
Once the user clicks in the axis I basically want to trigger some sort of selection process. The goal is to select the datapoints from the first click up until the mouse is clicked a second time. It is not obvious to me how I can infer from the cursor position (which i can extract) which of my datapoints is closest. Lets say I have plotted 1000 random datapoints, I dont know how a cursor position of say 200 could give me any idea about my real values.
Maybe some of you have encountered a similar problem and can help, that would be really great. Also if there may be a better solution, I am happy to hear it.
Thank you very much!!
For the button down function i was thinking about something along the line of:
selectedRegions = ;
% Button down function: RawEEG_ax
app.ax.ButtonDownFcn = @(hObject, evt) axclick(hObject,evt);
x = dataIdx1;
cp = hObject.CurrentPoint;
cx = cp(1,1);
selectedRegions(1) = round(interp1(x, 1:numDataPoints, cx, 'nearest', 'extrap'));
selectedRegions(2) = round(interp1(x, 1:numDataPoints, cx, 'nearest', 'extrap'));
I know there is also this datacursor mode, but I was hoping to find a better solution than using this, since I actually do not just want the indexes of te datapoints, but was hoping to have some more functionality once I have solved this first problem, e,g, live tracking of the cursor to visualize the selected region and I think for that purpose the datacursor mode is not optimal, so I wanted to try something else.
Allen 2023 年 5 月 19 日
What you are asking for sounds very much like what the brush data tool does. However, there are a few extra steps required to extract the data from the brushed data points. The following links provide guidance on this tool and how to extract data.
Brush Data Tool
Extracting data values from brushed points