Limiting UIAxes Interactivity in AppDesigner
Show older comments
Hi!
I'm using three UIAxes to display plots, and I'd like to be able to limit their interactivity such that the zoom in/out, and save/export buttons neither appear nor work. Are there commands to enable/disable these in AppDesigner?
Thanks in advance for your suggestions!
Accepted Answer
More Answers (2)
Mario Malic
on 12 Sep 2020
Edited: Mario Malic
on 13 Sep 2020
I am not aware of the option to save/export fig in App Designer.
For limiting interactivity:
ax = app.UIAxes; % change to your UIAxes handle
ax.Interactions = [panInteraction];
ax.Toolbar.Visible = 'off';
7 Comments
Adam Danz
on 13 Sep 2020
I believe OP is describing the toolbar options

Mario Malic
on 13 Sep 2020
Edited: Mario Malic
on 13 Sep 2020
I slightly modified my answer, as user doesn't want to zoom as I see.
Hiding toolbar does not remove zoom and pan capabilities, as they are also binded to mouse scroll and button pressed..
But that doesn't prevent the use of those tools in the toolbox. For example, I can still zoom by using the toolbar options after that line has been added to the startup function.
You're right that hiding the toolbar isn't enough to prevent default interactivity.
If the OP wants to prevent the default activity and allow for the toolbar usage, then your answer or the use of disableDefaultInteractivity may be the right approach. If the OP wants to prevent any possible any possible interaction, then they have to also turn off the toolbar.
Of course the user could use pan() and other interactive functions directly but they would also have to have the axis handle which isn't easy to get since the UIFigure's handlevisibility is off by default.
Mario Malic
on 13 Sep 2020
I haven't tested the toolbar buttons when I tried ax.Interactions = []; Looks like both answers are somewhat correct, I'll add the visibility option to my answer aswell, and let the OP judge based on his/her needs.
Yes, often answers are correct for some contexts and not a good fit for other contexts. That's what good about having multiple answers for a question. One may be perfect for this OP and the other may be perfect for a future visitor. The answers here will be valuable regardless of which answer is accepted. I enjoy and learn from other people's approaches such as this one.
"After disabling the interactions, you can still use the buttons in the axes toolbar to interact with the plot."
Mario Malic
on 13 Sep 2020
I sourced my information from UIAxes properties which also mentioned disableDefaultInteractivity, but didn't checked it.
"I enjoy and learn from other people's approaches such as this one." - Likewise!
Veena Chatti
on 22 Sep 2020
Bruno Gonfiotti
on 18 Sep 2020
0 votes
I tested the solutions here proposed, but in Matlab 2020b I get the following error: Invalid or deleted object. Error in disableDefaultInteractivity (line 12). ax.InteractionContainer.Enabled = 'off';
Do you have any suggestion?
8 Comments
Mario Malic
on 18 Sep 2020
You need to define ax to be the handle of the UIAxes you want to limit interactivity.
Bruno Gonfiotti
on 18 Sep 2020
Dear mario, thank you for your fast reply. I've done what you suggested, but i keep getting the same error...
Mario Malic
on 18 Sep 2020
Edited: Mario Malic
on 18 Sep 2020
"Invalid or deleted object" suggest that you're trying to apply the code to the object that doesn't exist (anymore?).
Can't suggest anything else, but to check if you wrote the correct name of component you're applying modification to.
disableDefaultInteractivity(app.myplotUIAxes) % check argument
Adam Danz
on 19 Sep 2020
I can confirm that both answers are functional in r2020b.
As Mario states, you have to use an axis handle that exists. For example, run this line and then apply either answer to the handle.
app.UIAxes = uiaxes();
or change the axis handle in either answer to match your existing axis handle.
Bruno Gonfiotti
on 21 Sep 2020
Edited: Bruno Gonfiotti
on 22 Sep 2020
Thank you all for your kind replies. I'll try today to figure out what I was doing wrong last friday.
UPDATE: Now it works. but I still don't know what I was doing wrong on Friday.
Adam Danz
on 22 Sep 2020
Thanks for the update, Bruno. That function (disableDefaultInteractivity) receives one variable, an axis handle. From the error message we can gather that you were either providing a value that isn't an axis handle (e.g. maybe a figure handle or an axis handle with a typo) or a handle to an axis that was deleted. Perhaps the variable that stored your axis handle was overwritten with a different value.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!