Does the base Matlab have something similar to Java's command 'setDefaul​tCloseOper​ation'?

7 ビュー (過去 30 日間)
Jordan
Jordan 2022 年 11 月 17 日
回答済み: Steven Lord 2022 年 11 月 17 日
So for context, I have created a plot that simulates objects moving within a 2D plot with a bunch of other mechanics and whatnot, but I was specifically wondering if there was a way to stop the program, or for the program to be able to detect when the created plot window has been closed by the user? I have looked into the
status = close('all','hidden')
command from, but I don't entirely know the syntax of the command to get the result I'm looking for.
Thanks in advance. :)

回答 (2 件)

Bruno Luong
Bruno Luong 2022 年 11 月 17 日
  2 件のコメント
Jordan
Jordan 2022 年 11 月 17 日
The usage description is a bit confusing, do I have to create 2 more figures for the function to work properly?
Bruno Luong
Bruno Luong 2022 年 11 月 17 日
No you set the callback 'DeleteFcn' of the speific figure where you want to detect the event when user close it.

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


Steven Lord
Steven Lord 2022 年 11 月 17 日
If you want to detect if a handle is a valid Handle Graphics object, use ishghandle.
f = figure;
f2 = figure;
x = 42;
close(f)
ishghandle([f, f2])
ans = 1×2 logical array
0 1
ishghandle(x)
ans = logical
0
f is not a valid handle because the figure has been deleted.
disp(f)
handle to deleted Figure
If you want to intercept the figure window closing (to avoid closing or to do something before closing the window) consider defining a CloseRequestFcn for your figure instead of a DeleteFcn. See the entry for this property in the Window Callback sections of the Figure properties or UI Figure properties documentation pages for more information.

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by