Borrar filtros
Borrar filtros

How to prevent images/axis from moving around

43 visualizaciones (últimos 30 días)
Joseph Henry
Joseph Henry el 21 de Jul. de 2019
Comentada: Ahmad el 19 de Oct. de 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 comentarios
Joseph Henry
Joseph Henry el 23 de Jul. de 2019
Editada: Joseph Henry el 23 de Jul. de 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 el 19 de Oct. de 2023
@Joseph Henry how did you figure it out? Please post your code if you don't mind, I'm facing the same problem

Iniciar sesión para comentar.

Respuestas (1)

Ahmad
Ahmad el 19 de Oct. de 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 comentarios
Adam Danz
Adam Danz el 19 de Oct. de 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 el 19 de Oct. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by