MATLAB: Close all hidden problem

close all hidden problem

I want to close the invisible figure in an app, but after I use command: close all hidden, the apps are becomes 'invalid or deleted objects'
close all hidden will only close figures including invisible figures, not apps. so…is there any mistake with my operation?
Thanks!
Yu

Best Answer

Did you type those inside a function or in the command window?
h=figure(5);
figHandles = get(groot, 'Children')
For example,
h=figure(5);
figHandles = get(groot, 'Children');
clear h % clears the variable in the workspace
close(h) % h is deleted so it will obviously give an error.
close(figHandles) % figHandles is an instance of figure object. This should close your figure even if you deleted h from the workspace.
% be sure about which workspace you are working in.
If you create your figure in a function and if the function does not include any close action, after that function executed, you can't close it because your workspaces has changed from "function workspace" to "base workspace". If this is your case, add an output value to your function which is the handle of your figure object. (in here it is "h").
Check out below link:
Also that might be useful:
You should read more about handle classes to understand what happens when you create an instance of an object.
Here is the link: