MATLAB: Get line plot data just by mouse stay on it (without click)

cursor ata

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?

Best Answer

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