Delete only figure objects from workspace MATLAB 2015a

조회 수: 3 (최근 30일)
Håvard
Håvard 2015년 6월 17일
댓글: Håvard 2015년 6월 18일
I just started using matlab with the new figure handles which now no longer are just a number, but an object of sorts.
Currently I am working with som old scripts that store a lot of different figure handles which I need to delete. I can obviously delete them one at a time, but its a lot of objects, and the names may vary every time the script run.
The reason that I need to delete the handles is that I need to store the entire workspace except for the figure handles as they produce a warning in 2015a (and possible earlier releases?).
Is there a way to use functions like clear() to delete only figure handles from the workspace in 2015a?

채택된 답변

Guillaume
Guillaume 2015년 6월 17일
편집: Guillaume 2015년 6월 17일
As per the documentation of close:
close all deletes all figures whose handles are not hidden.
close all hidden deletes all figures including those with hidden handles.
close all force deletes all figures, including GUIs for which CloseRequestFcn has been altered to not close the window.
Note that you can also pass an array of handles to delete which should have the same effect.
  댓글 수: 3
Guillaume
Guillaume 2015년 6월 17일
It's probably semantics but close does delete the handle:
>>hfig = figure;
>>close all
>>hfig
hfig =
handle to deleted Figure
What I think you meant is you want to clear the variable from your workspace. Since clear only has a command form it's going to be difficult to do programmatically. However, you can certainly store the entire workspace but figure handles programmatically:
allvars = whos;
nonfigurevars = {allvars(~strcmp({allvars.class}, 'matlab.ui.Figure')).name};
save('somefile.mat', nonfigurevars{:});
Håvard
Håvard 2015년 6월 18일
Thank you again. When i use the first method you propose using close all, no figure handles are removed from my workspace.
The other method, however, works just great. I didn't think of doing it that way.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by