How can I infer from the data cursor position, the index of the closest datapoint
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Julian Ostertag
el 19 de Mayo de 2023
Comentada: Julian Ostertag
el 22 de Mayo de 2023
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 comentarios
Respuesta aceptada
Allen
el 19 de Mayo de 2023
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Historical Contests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!