Strange Behaviour using Zoom with app designer

Hello. I have an image on a UIAxes and want to use a checkbox to either zoom in 4X, or retrun to 1x.
I have tried this:
value = app.xZoomCheckBox.Value;
switch value
case 1
zoom(app.UIAxes,'reset') % Sets baselevel zoom
zoom(app.UIAxes,4) % Zoom 4x
case 0
zoom(app.UIAxes,'out') % Return to baselevel zoom
end
with the checkboxclicked (case 1), the image does zoom in 4x.
However when I unclick the checkbox (case 0), I get the error message
Unrecognized function or variable 'firstinput'.
Error in matlab.graphics.interaction.webmodes.zoomWeb
I have also tried zooming 1x, but this did nothing.

 Akzeptierte Antwort

Adam Danz
Adam Danz am 3 Nov. 2020
Bearbeitet: Adam Danz am 3 Nov. 2020

0 Stimmen

According to the documentation, the zoom() function can receive a figure handle as input, not an axes handle. Zoom is applied to the current axes within the figure.
If you call zoom(app.UIFigure,'out') with a figure handle, it works.
Note that you can change the current axes programmatically by setting
figureHandle.CurrentAxes
The weird thing is that the function breaks with axes inputs when the 'out' option is used (and maybe others) but not with 'reset' or factor values. Too bad the section of code that receives the inputs is wrapped in p-code.

4 Kommentare

Jason
Jason am 3 Nov. 2020
Hi, thanks.
So do I have to apply the 'out' to the whole figure. I have several UIAxes and only want to apply to one of them
Yes. As my answer states, the zoom is applied to the current axes on the figure and you can control which axes is current either by clicking on the axes or setting it programmatically using the CurrentAxes property of the figure.
So the workflow would look like this,
app.UIFigure.CurrentAxes = app.UIAxes1;
zoom(app.UIFigure, 'out')
Adam Danz
Adam Danz am 4 Nov. 2020
Glad I could help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020b

Gefragt:

am 3 Nov. 2020

Kommentiert:

am 4 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by