How to get mouse coordinates in GUI (AppDesigner) ?

조회 수: 16 (최근 30일)
Mohit Kumar
Mohit Kumar 2020년 10월 2일
댓글: Ameer Hamza 2020년 10월 8일
I am using MATLAB App Designer and have inserted axes into the app.
When the user clicks a button, I want them to be able to then select a point on the axes. Basically, the functionality should be identical to ginput.
How should I do this? I am aware that related questions have been asked but am honestly not able to understand parts of those or the solutions don't seem to work well. It looks to be something to do with using ButtonDownFcn callback and CurrentPosition but I'm not able to understand how to use these.
Thanks for your help!
Mohit.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 2일
편집: Ameer Hamza 2020년 10월 2일
Check the attached app for the demo.
  댓글 수: 2
Mohit Kumar
Mohit Kumar 2020년 10월 5일
편집: Mohit Kumar 2020년 10월 8일
EDIT : My code seemed to not be working because I was using tabs in my app. Removing the tabs made the code work just fine. Most weird.
Hi Ameer, thanks for the answer. It works perfectly in the app that you sent. However, when I implement it in my code, the Y coordinate seems to be "shifted" by -3.5 coordinates. I've tried to explain this with the picture attached. Here is my code, I don't see anything wrong with it...
% The function for ButtonPushedFcn
function fixed_pts_guess(app,ax,eve)
x_pt = ax.CurrentPoint(1,1);
y_pt = ax.CurrentPoint(1,2);
app.FixedPtsTextArea.Value=num2str([x_pt y_pt]);
end
% The callback function where the implementation happens
function GuessSolutionButtonValueChanged(app, event)
value = app.GuessSolutionButton.Value;
if value % If button is switched on
app.FixedPointsAxes.ButtonDownFcn=@app.fixed_pts_guess;
else
app.FixedPointsAxes.ButtonDownFcn='';
end
end
Ameer Hamza
Ameer Hamza 2020년 10월 8일
This might be some bug. You may consider filing a bug report: https://www.mathworks.com/support/bugreports/report_bug

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by