#GCF MATLAB 2017 UPDATE#
If axes are added to or removed from the figure, you will need to call full_crosshair again to update 'WindowButtonMotionFcn' accordingly.
#GCF MATLAB 2017 CODE#
If any of the axes limits change, then the event listeners in the above code will detect and account for it. Then as you move the cursor over each axes in your figure the cursor will disappear and you will see two lines appear and track the mouse position. If you do the following: full_crosshair(gcf) Actually, it is better to use handles than gcf as gcf uses the last figure that was addressed, example. Always obtain, pass, and use graphics handles. You can change where each is placed and the dimensions. Do no use gcf or gca for code that you want to work properly. If no figure exists, MATLAB creates one and returns its handle. The current figure is the figure window in which graphics commands such as plot, title, and surf draw their results. Set(hHoriz(~inAxes), 'YData', nan(1, 2)) That will have the two figures with exactly the same size, and in the same position. gcf (MATLAB Functions) Get current figure handle Syntax h gcf Description h gcf returns the handle of the current figure. ListenObj(iAxes) = addlistener(hAxes(iAxes),, num2cell(cursorPos(inAxes, 1)*, 2)) HVert(iAxes) = line(nan(1, 2), yLimits(iAxes, :), 'Parent', hAxes(iAxes)) HHoriz(iAxes) = line(xLimits(iAxes, :), nan(1, 2), 'Parent', hAxes(iAxes))
% Create lines (not displayed yet due to NaNs) and listeners:
HAxes = findall(hFigure, 'Type', 'axes')
Here's a function that creates such functionality for all axes in a figure: function full_crosshair(hFigure) ahmadfiryal in Engineering, Optimization in Power System Operation OctoOcto304 Words Generation Cost Function for Power Plant Using Linear and Quadratic Programming Asslamu’alaikum Brother and Reader this blog. You can actually do this by adding a 'WindowButtonMotionFcn' to your figure (assuming nothing else is using it) that will display crosshair lines in your axes when your mouse is over it.