close all hidden problem

15 ビュー (過去 30 日間)
Yu Li
Yu Li 2019 年 1 月 4 日
コメント済み: Luna 2019 年 1 月 11 日
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
  8 件のコメント
Stephen23
Stephen23 2019 年 1 月 7 日
編集済み: Stephen23 2019 年 1 月 7 日
"but according to this page: https://www.mathworks.com/help/matlab/ref/close.html close all hidden will only close figures including invisible figures, not apps"
I searched that page for the word "app" and it only occurs once in a link below the help itself. Why do you think that close does not apply to apps? I don't see that written anywhere on that page.
In any case, writing close all is a sledgehammer approach to writing code. While it might be fun and useful from the command line, coding something like that into any app, GUI, or function is like shooting yourself in the knee. Instead of writing such brutal, uncontrolled code, learn how to obtain and use explicit handles for all graphics objects that you use:
Once you learn to use graphics object handles then your code will be much more robust, reliable, and easier to debug.
Yu Li
Yu Li 2019 年 1 月 7 日
Hi:
Please allow me some time to prepare a test app for you.
Thank you!
Yu

サインインしてコメントする。

採用された回答

Luna
Luna 2019 年 1 月 4 日
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:
  2 件のコメント
Yu Li
Yu Li 2019 年 1 月 7 日
Thank you luna, I think this resolve my question.
Bests,
Yu
Luna
Luna 2019 年 1 月 11 日
Your welcome ;) Please accept answer if it works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by