App designer: how to get mouse position when I click on figure?

조회 수: 169 (최근 30일)
Maxime Hervo
Maxime Hervo 2018년 6월 19일
편집: Walter Roberson 2021년 6월 8일
Good afternoon,
I am converting Programmatic GUI to app designer. I want to get the mouse position when a user click on a figure.
Unfortunately the CurrentPoint property is not available on the UIaxes. is there a work around?
(Since 2017a we can use the buttonBown property but I do not see the point if we do not know where the user clicked buttonDown )
Thanks a lot, Maxime
  댓글 수: 7
Eric Sargent
Eric Sargent 2020년 12월 9일
As of R2020b you can use the ginput function to get the coordinates of a selected point in an axes.
(Full answer below)
Paul Ben Ishai
Paul Ben Ishai 2021년 1월 4일
You sir, are a genius! It works like a treat!

댓글을 달려면 로그인하십시오.

답변 (3개)

Siwan Yang
Siwan Yang 2018년 6월 22일
Hello Maxime,
You could use the ‘ImageClickCallback’ function mentioned in the article to get the mouse click coordinate. You could also use ‘ginput’ function to adjust the number of coordinates you want to get.
Thanks,
Siwan

Charles Pruszynski
Charles Pruszynski 2019년 12월 24일
편집: Walter Roberson 2021년 6월 8일
The ROI selection functions of the Image Processing Toolbox can do this in App Designer:
roiPOC = drawpoint(app.UIAxes); %Use Mouse To Select a point ROI
PosPOC=round(get(roiPOC,'Position')); %Extract Coordinates of the point ROI
delete(roiPOC); %Delete the point ROI Marker
drawnow; % Force figure update
CJP
  댓글 수: 2
Andrew Diamond
Andrew Diamond 2020년 5월 2일
I used this to good effect. Thanks
I'm sure you already know this, but you have roiPOA vs roiPOC typos
For posterity: odd notes for drawpoint on uiaxes vs axes
1) The cursor doesn't change to a cross hair (or the like)
2) If you don't delete the point obect (i.e. the deletion of the returned point object), as shown, and then you right click for the context menu, it throws an error. So its deletion is a practical necessity.
Charles Pruszynski
Charles Pruszynski 2020년 5월 2일
Thanks. Fixed the typos.
CJP

댓글을 달려면 로그인하십시오.


Eric Sargent
Eric Sargent 2020년 12월 9일
As of R2020b you can use the ginput function to get the coordinates of a selected point in an axes.
It requires a specific setup as noted in the documentation (see link below):
The ginput and gtext functions do not have an argument for specifying the target figure. As a result, you must set the HandleVisibility property of the App Designer figure to 'callback' or 'on' before calling these functions. After you call these functions, you can set the HandleVisibility property back to 'off'. For example, this code shows how to define a callback that allows you to identify the coordinates of two points using the ginput function.
function pushButtonCallback(app,event)
app.UIFigure.HandleVisibility = 'callback';
ginput(2)
app.UIFigure.HandleVisibility = 'off';
end

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by