-1

I am creating a real time MATLAB demo and I need to select a point of interest by clicking on the axes. In general, the system works fine and I am able to modify the variables using the ButtonDownFcn. However the following problem occurs

When I plot other data (such as a scatter plot) on the same axis, the ButtonDownFcn does not seem to be triggered if I click on the scatter plot rather than the axes where there is no plot. There are no errors.

This is an issue because my scatter plots can be quite dense and the point I would like to click on lies underneath of the plot object.

How can I make it so that all mouse clicks are registered by the axes so that my ButtonDownFcn gets executed on every click.

Suever
  • 64,497
  • 14
  • 82
  • 101
Maja
  • 51
  • 1

1 Answers1

1

You want to utilize the HitTest property to disable the ability of all other graphics objects to respond to a mouse click.

If you want to only enable clicks on the axes something like this should work.

% Disable callbacks for all objects within the current axes
set(findall(gca), 'HitTest', 'off')

% Enable click events for the axes and set the buttondownfcn
set(gca, 'HitTest', 'on', 'ButtonDownFcn', callback)
Suever
  • 64,497
  • 14
  • 82
  • 101