get line plot data just by mouse stay on it (without click)

조회 수: 5 (최근 30일)
Morteza
Morteza 2013년 1월 27일
댓글: Ouael Chkoundali 2019년 2월 25일
I plot my data and I need to show data (Y) in text box when I put the mouse cursor on it (without click), is there any fuction that help me?

채택된 답변

Teja Muppirala
Teja Muppirala 2013년 1월 28일
Here is a simple example that outlines how to do it using HITTEST.
function my_example
plot(rand(5));
set(gcf,'windowbuttonmotionfcn',@getcoords)
function getcoords(varargin)
this = hittest;
if strcmp(get(this,'type'),'line');
cp = get(gca,'currentpoint');
ht = title(num2str(cp([1 3])));
set(ht,'color',get(this,'color'));
end
  댓글 수: 1
Ouael Chkoundali
Ouael Chkoundali 2019년 2월 25일
Hi Teja,
and if I want to display the mouse position only when it is on an axes? I have a GUI with 1 axes and buttons.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2013년 1월 28일
datacursormode() with a custom callback function that sends the coordinate to the edit box as well as displaying it on the screen.
  댓글 수: 1
Morteza
Morteza 2013년 1월 28일
I knew that datacursormode can return current position mose on the figure, but it is require to call the function and the click on the screen to get result. In my plot just by move the mouse program should realize that current mouse position is on the line plot if you are already. I found a function like overobj2.m and put it in the function that is called by my program every secound to get data, but it just return only axes .....

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


Jan
Jan 2013년 1월 28일
You can use the WindowsButtonMotion function of the parent figure. There OVEROBJ can check, if the mouse is over the specified axes and the CurrentPoint property of this axes contains the coordinates. Now you need a method to find the nearest (interpolated?) point of your data for the display.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by