필터 지우기
필터 지우기

How to prevent images/axis from moving around

조회 수: 43 (최근 30일)
Joseph Henry
Joseph Henry 2019년 7월 21일
댓글: Ahmad 2023년 10월 19일
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