How to prevent images/axis from moving around
51 views (last 30 days)
Show older comments
Hi,
I have a GUI made with App Designer that allows the user to draw elliptical ROI's on an image. Because the user might need to make small adjustments, I don't want the image/axis to move around when the user clicks on it (in the event that they are trying to adjust an ROI and accidentally click the image instead). In other words, if the user clicks and drags on the image itself (but not the ROI) I do not want the image to move.
While I was using R2018, this seemed to work just fine for the above problem:
disableDefaultInteractivity(app.myAx)
However, this no longer appears to work in R2019a. Does anyone have an alternative/fix?
EDIT: For anyone who has the same issue, it appears that you must call the above command after you display an image on the axis as well.
6 Comments
Ahmad
on 19 Oct 2023
@Joseph Henry how did you figure it out? Please post your code if you don't mind, I'm facing the same problem
Answers (1)
Ahmad
on 19 Oct 2023
This one worked for me
% Store current X and Y limits
xLimits = app.UIAxes.XLim;
yLimits = app.UIAxes.YLim;
% Draw your shapes or add data here
% Restore them
app.UIAxes.XLim = xLimits;
app.UIAxes.YLim = yLimits;
2 Comments
Ahmad
on 19 Oct 2023
@Adam Danz I ran into the issue of not having 'hold on' but fixed it with this code on startup:
ax = app.UIAxes;
ax.XLim = [-100 100];
ax.YLim = [-100 100];
But I've just tried 'hold on' and it seems more reasonable, thanks!
I could change it back to how it was since 'hold on' requires me to zoom out which sometimes doesn't work quite well.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!