필터 지우기
필터 지우기

Find the coordinates of a point chosen on a plot

조회 수: 63 (최근 30일)
Nom
Nom 2019년 11월 12일
댓글: Fangjun Jiang 2023년 5월 9일
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
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
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
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 ?
Fangjun Jiang
Fangjun Jiang 2023년 5월 9일
pdist2() comes from Statistics and Machine Learning Toolbox.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2019년 11월 12일
Use data cursor, set "SnapToDataVertex" to be "on" and then get the position. See example in
doc datacursormode
  댓글 수: 1
Nom
Nom 2019년 11월 13일
편집: Nom 2019년 11월 13일
Is there a way to do this using ginput, at least where I can see the x-line and y-line of the crosshair which chooses the point?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by