Azzera filtri
Azzera filtri

How can I get the mouse position on an image after uploading it on axes

2 visualizzazioni (ultimi 30 giorni)
Hi,
I want to display the mouse position on my GUI. The problem is that it works on the axes. But after uploading the image it doesn't work any more. What is the problem? Or is there any other possibility to do it?
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
c = get (gca, 'CurrentPoint');
x = c(1,1);
y = c(1,2);
set(handles.xPos, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.yPos, 'string', ['y loc:' num2str(y)]); % update text for y loc

Risposte (1)

Guillaume
Guillaume il 20 Dic 2018
By default Image objects capture mouse clicks. So if an Image is displayed in an axes, when you click on it it's the ButtonDownFcn of the Image that gets called, not the axes one.
You can easily turn that off but setting the HitTest property of the Image to off.
%image creation using either imhsow, image, imagesc, whatever...
himage = imshow(something)
himage.HitTest = 'off'; %image won't capture mouse clicks, the axes will instead.
  1 Commento
Ouael Chkoundali
Ouael Chkoundali il 22 Dic 2018
Hi Guillaume,
thanks for your answer. Is there any possibility to show the mouse position without clicking on the axes? It works on a figure but i couldn't do it on axes?

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by