Help: delete(axis) doesn't delete the axis object but only removes the plot in App-Designer
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Tommy
2020-4-21
编辑:Tommy
2020-4-22
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interaction Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!