Help: delete(axis) doesn't delete the axis object but only removes the plot in App-Designer
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I'm creating a plotting app where users can add/delete plots manually. I programmatically create the axes in my app using 'uiaxes' function and add a toolbarpushbutton which allows users to delete that plot.
It turns out that only the plot disappears but the axis object isn't deleted after I click the button.
The axis object is only deleted when 'the app is closed'. I want to clear up my memory and explicitly delete them.
I am using matlab 2020a on MAC PRO.
Is there a solution to this?
I also attached the app if you guys can take a look.
Best,
Toey
0 commentaires
Réponse acceptée
Tommy
le 21 Avr 2020
Modifié(e) : Tommy
le 22 Avr 2020
For some reason, evnt.Axes in your toolbar button callback is not equal to the corresponding axes that you store within app.myaxes. I'm a little confused, but I think it might be related to the following, which you can run yourself at the command window:
>> ax = uiaxes;
>> isequal(ax, ax.Toolbar.Parent)
ans =
logical
0
and
>> class(ax)
ans =
'matlab.ui.control.UIAxes'
>> class(ax.Toolbar.Parent)
ans =
'matlab.graphics.axis.Axes'
The documentation for UIAxes says you can use axtoolbar on UIAxes objects, but when you do so, the parent of the new toolbar is set equal to the parent of the previous toolbar, which as shown above is clearly not the UIAxes in question. Maybe it is a bug that the UIAxes' toolbar's Parent property seems to refer to a regular old Axes, or maybe I am just misunderstanding something.
At any rate, you can solve your issue by passing in the specific axes to your toolbar button callback instead of using the axes stored in evnt.Axes:
btn.ButtonPushedFcn = {@(~,~,ax) (delete(ax)), ax}; % Click on this tool to delete axis
(edit) Just to show that the above is only true for UIAxes:
>> ax = axes;
>> isequal(ax, ax.Toolbar.Parent)
ans =
logical
1
(edit #2) Above was done in R2019a.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interaction Control dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!