필터 지우기
필터 지우기

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

채택된 답변

Tommy
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 CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by