Help: delete(axis) doesn't delete the axis object but only removes the plot in App-Designer
3 ビュー (過去 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!