Limiting UIAxes Interactivity in AppDesigner

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

Adam Danz
Adam Danz on 13 Sep 2020
Edited: Adam Danz on 13 Sep 2020
The first line below turns off default interactivity and the second line turns off the toolbar options.
disableDefaultInteractivity(app.UIAxes)
app.UIAxes.Toolbar.Visible = 'off';

More Answers (2)

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

I believe OP is describing the toolbar options
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..
Adam Danz
Adam Danz on 13 Sep 2020
Edited: Adam Danz on 13 Sep 2020
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.
Even disableDefaultInteractivity(ax) does not disable the toolbar options.
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.
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.
Adam Danz
Adam Danz on 13 Sep 2020
Edited: Adam Danz on 13 Sep 2020
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.
BTW, from the documentation,
"After disabling the interactions, you can still use the buttons in the axes toolbar to interact with the plot."
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!
Thank you both for your inputs! I found that Adam's answer worked!

Sign in to comment.

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

You need to define ax to be the handle of the UIAxes you want to limit interactivity.
Dear mario, thank you for your fast reply. I've done what you suggested, but i keep getting the same error...
"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
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.
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.
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.
Ioannis
Ioannis on 24 Aug 2022
Moved: Adam Danz on 25 Aug 2022
How can I use disableDefaultInteractivity for all the functions?
@Ioannis, can you explain what you mean by "functions"? Do you mean interactions? What interactions still existed after executing disableDefaultInteractivity?

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 12 Sep 2020

Commented:

on 25 Aug 2022

Community Treasure Hunt

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

Start Hunting!