How to show the position of your mouse in a GUI that has two Axes?

11 ビュー (過去 30 日間)
Meshooo
Meshooo 2016 年 2 月 8 日
コメント済み: Adam Danz 2020 年 6 月 16 日
Dear all,
I have a GUI that has two axes, Main_Axes and Side_Axes.
Now I want when mouse is over a point in the Main_Axes, it will show the same position of the mouse in the Side_Axes.
So I made a function that I called 'mouseMove', that start * the mouse position
function mouseMove (object, eventdata)
C = get (gca, 'CurrentPoint');
X = C(1,1);
Y = C(1,2);
I = getimage;
hold on
plot(X, Y, 'y*')
hold off
Now in the callback I add this code
set(handles.Main_Axes,'HandleVisibility','ON');
set(handles.Side_Axes,'HandleVisibility','OFF');
imshow(I) % to show 'I' in the Main_Axes
axes(handles.Side_Axes)
set (gca, 'WindowButtonMotionFcn', @mouseMove);
This makes the yellow star always appear in the Main_Axes, but it should appear in the Side_Axes.
Any idea how to fix that?
Meshoo

採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 9 日
set (gca, 'WindowButtonMotionFcn', {@mouseMove, handles});
function mouseMove(object, eventdata, handles)
if ~isfield(handles, 'side_pointer') || ~ishandle(handles.side_pointer)
pointersize = 30;
handles.side_pointer = scatter(nan, nan, pointersize, 'y', 'Marker', '*');
guidata(object, handles);
end
C = get(handles.Main_Axes, 'CurrentPoint');
x = C(1,1); y = C(1,2);
%move the cursor
set(handles.side_pointer, 'XData', x, 'YData', y);
%zoom around the cursor
zoomwidth = 64;
xleft = max(0, x-zoomwidth/2);
ybot = max(0, y-zoomwidth/2);
set(handles.Side_Axes, 'XLim', [xleft xleft+zoomwidth], 'YLim', [ybot ybot+zoomwidth]);
drawnow();
  2 件のコメント
Meshooo
Meshooo 2016 年 2 月 9 日
That's work well. Thank you very much.
Adam Danz
Adam Danz 2020 年 6 月 16 日
If I'm not mistaken, I think that first line should be
set(gcf, . . . )
WindowButtonMotionFcn is a figure property.

サインインしてコメントする。

その他の回答 (2 件)

John BG
John BG 2016 年 2 月 8 日
Hi Meshoo
may be you can modify GetMousePosition.m to achive
'when mouse is over a point in the Main_Axes, it will show the same position of the mouse in the Side_Axes.'
what is the purpose of doing so?
  1 件のコメント
Meshooo
Meshooo 2016 年 2 月 9 日
Thank you for the link. I didn't explain the purpose from that because I don't want to make it more complicated. So the idea is to show a zoom in the Side_Axes of the same point where the mouse is over in the Main_Axes. This will help the user to see more details in the Side_Axes.
Do you know any one tried to do similar thing?

サインインしてコメントする。


Ruben Gaitan Ortiz
Ruben Gaitan Ortiz 2018 年 11 月 16 日
I had a similar problem. Thank you!

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by