Help: delete(axis) doesn't delete the axis object but only removes the plot in App-Designer
9 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Tommy
on 21 Apr 2020
Edited: Tommy
on 22 Apr 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.
More Answers (0)
See Also
Categories
Find more on Interaction Control in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!