MATLAB: How to define callbacks for a GUI when the cursor clicks on or hovers over a UIAxes within App Designer

appbuttoncallbacksclickdesignerMATLABmotionuiaxesuifigure

I am trying to create an app in App Designer and would like to change what is being plotted based on the cursor location as well as when the axis is clicked. This used to be available within the 'Axes' Object, but this property does not appear for 'UIAxes'. Is there a workaround?

Best Answer

The 'UIAxes' object does not have an object property similar to that of the 'ButtonDownFcn' for 'Axes' objects.
In addition, 'Axes' objects do not have a property related to hovering the cursor over the axis.
However, both of these goals can be met by use of 'UIFigure' callbacks. You can use the following steps
1) Establish UIFigure callback -
There is a small walkthrough of how to use 'UIFigure' callbacks within the following documentation.
If you would like a full list of the UIFigure callbacks, they can be found within the following documentation.
2) Access the cursor location -
We can use the following code within the callback function.
Coordinates = event.Source.CurrentPoint;
'Coordinates' now stores an array containing the coordinates of the cursor in units of pixels.
3.) Compare these coordinates to the location of the 'UIAxes' -
We can extract the position of the UIAxes using the 'Position' property. For example
Position=app.UIAxes.Position; %Get the axes position
This workflow is demonstrated in the attached example. The circle in the graph moves with the cursor and grows larger whenever you click within the area of the plot.