Selecting the nearest data point in a 2-D plot
9 views (last 30 days)
Is it possible to select the nearest data point rather select any point on the graph? I have seen "ginput" and "getpts" function. Both of these select the point that we click not the nearest data point.
For example you can view thw bottom code
x = 0:0.1:10;
za = C;
y = (x.^za);
hg = figure(1);
[xda(:,C),yda(:,C)] = ginput(2);
%[xda(:,C),yda(:,C)] = getpts(hg);
Ajay Kumar on 5 Nov 2019
Edited: Ajay Kumar on 5 Nov 2019
Try to perform difference (and take minimum of absolute) between both ginput data point and original data and take out the index.
[val,idx]=min(abs(ginput_data - original_data));
then use this idx to go to the original data (which is the nearest point) instead of any point on axes.