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_exampleplot(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 Related SolutionsMATLAB: WindowButtonDownFcn conflicting with ButtonDownFcn You can insert an axes object spanning this whole figure as a background and use its ButtonDownFcn:BGcolor = get(0, 'DefaultFigureColor');BGaxes = axes('Units', 'normalized', 'Position', [0,0,1,1], ... 'XTicks, [], 'YTicks', [], ... 'Color', BGcolor, 'XColor', BGcolor, 'YColor', BGcolor, ... 'ButtonDownFcn', 'disp(''Background'')');DataAxes = axes('ButtonDownFcn', 'disp(''Data'')'; MATLAB: How to continuously read the mouse position as the mouse is moving only on axes on a figure See https://blogs.mathworks.com/videos/2008/05/27/advanced-matlab-capture-mouse-movement/Use the 'WindowButtonMotionFcn' and display the changes only, when the mouse is over the axes. You can do this either by comparing the coordinates or maybe by the undocumented function hittest(FigHandle), which replies the object is mouse is over. See also: https://www.mathworks.com/matlabcentral/answers/219797-check-if-mouse-is-above-an-axes, especially the command overobj. Related QuestionHittest axes with WindowWheelScrollFcn callbackUIContextMenus for toggle buttonsButtonDownFcn return map coordinatesDynamically reading cursor location
Best Answer