How to prevent images/axis from moving around

43 次查看(过去 30 天)
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 个评论
Joseph Henry
Joseph Henry 2019-7-23
编辑:Joseph Henry 2019-7-23
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 2023-10-19
@Joseph Henry how did you figure it out? Please post your code if you don't mind, I'm facing the same problem

请先登录,再进行评论。

回答(1 个)

Ahmad
Ahmad 2023-10-19
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 个评论
Adam Danz
Adam Danz 2023-10-19
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 2023-10-19
@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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by