how to select an axis using mouse click?

I have 2 axes in the gui figure window. I want to plot the data on the selected axis. The selection is to be done with a mouse click. How do i do it? please help.

Respuestas (2)

Adam
Adam el 14 de Abr. de 2015
Editada: Adam el 15 de Abr. de 2015
Axes have a
ButtonDownFcn
property. Just define a callback in each of your axes that allows you to identify which was selected. Probably you could use the same callback for both as the src (first argument to the callback) should allow you to identify the axes by comparing it with the two axes handles.
Jan
Jan el 14 de Abr. de 2015

0 votos

If you click on an axis, is is made the current axes object automatically. But this might be confusing for the user, because this action does not change anything on the screen. So following the ButtonDownFcn advice of Adam is a good idea.

3 comentarios

Aru hazari
Aru hazari el 14 de Abr. de 2015
Ok but there is an object on the axis already. And I am not able to turn off the hitTest option for the object. How do I get the access to the axis itself? The button down function doesn't work because of the object
You can use the
WindowButtonDownFcn
of the figure itself, but then you have to manually work with the position coordinates and compare them to the 'Position' property of your axes.
Alternatively you could use a callback on whatever object is on your axes (and retrieve its parent), but that may not be an appropriate solution depending what is plotted, how often it changes, etc, etc.
Alternatively you could just use a radio button to choose axes instead of clicking on them. Or a toggle button.
Steven Zhu
Steven Zhu el 22 de Sept. de 2022
Hi Jan,
Yes, your are right. I'm confusing about current axes object changed automatically by clicking it accidentally.
Do you know any way to turn it off? Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Data Exploration en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Abr. de 2015

Comentada:

el 22 de Sept. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by