Find the coordinates of a point chosen on a plot
108 次查看(过去 30 天)
显示 更早的评论
Hello,
So I've been using ginput to select points on a plot
My plot consists of time(x) and velocity(y).
Below is my user-selected points.
[Userx,Usery] = ginput(1);
However, I noticed it doesn't actually select points from the voltage vs. time graph and instead just a point in the figure screen.
How can I get the nearest data point of the actual plot?
I've found one solution is to use this user created script file:
https://www.mathworks.com/matlabcentral/fileexchange/3265-magnetginput
1 个评论
Dinuka Madhumal
2023-5-9
Can anyone help me, what is the problem of this error - Undefined function or variable 'pdist2'. . Do i want to make the 'pdis2' function ?
采纳的回答
darova
2019-11-14
Short example
x = linspace(0,2,20)'; % generate some data
y = sin(x);
plot(x,y,'.-b')
xy = ginput(1); % get point
[~,ix] = min(pdist2([x y],xy)); % find closest point
hold on
plot(x(ix),y(ix),'or') % display closest point
hold off
3 个评论
Dinuka Madhumal
2023-5-9
Can anyone help me, what is the problem of this error - Undefined function or variable 'pdist2'. . Do i want to make the 'pdis2' function ?
更多回答(1 个)
Fangjun Jiang
2019-11-12
Use data cursor, set "SnapToDataVertex" to be "on" and then get the position. See example in
doc datacursormode
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!