How can I infer from the data cursor position, the index of the closest datapoint
10 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
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);
function axclick(hObject,evt)
x = dataIdx1;
cp = hObject.CurrentPoint;
cx = cp(1,1);
if isempty(selectedRegions)
selectedRegions(1) = round(interp1(x, 1:numDataPoints, cx, 'nearest', 'extrap'));
else
selectedRegions(2) = round(interp1(x, 1:numDataPoints, cx, 'nearest', 'extrap'));
end
end
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.
0 个评论
采纳的回答
Allen
2023-5-19
Julian,
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!