How to prevent images/axis from moving around

43 views (last 30 days)
Joseph Henry
Joseph Henry on 21 Jul 2019
Commented: Ahmad on 19 Oct 2023
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
Joseph Henry
Joseph Henry on 23 Jul 2019
Edited: Joseph Henry on 23 Jul 2019
I believe so. Here is the relevant code. What am I missing?
% Creates axes and clears the axes component of title, x & y labels, and ticklabels
app.myAx = axes(app.UIFigure, 'Units', 'Pixels', 'Position',[39,413,800,450], 'XTick', [], 'YTick', []);
title(app.myAx, []);
xlabel(app.myAx, []);
ylabel(app.myAx, []);
app.myAx.XAxis.TickLabels = {};
app.myAx.YAxis.TickLabels = {};
disableDefaultInteractivity(app.myAx)
EDIT: I figured it out. Much thanks!
Ahmad
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

Sign in to comment.

Answers (1)

Ahmad
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
Adam Danz
Adam Danz on 19 Oct 2023
Thanks for sharing, @Ahmad. Note that this will successfully return the axis limits to the stored values but it may not prevent the axis limits from changing. Your answer combined with hold(app.UIAxes,'on') would fix that issue
Ahmad
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!