How to detect whether a figure is created by uifigure()

30 ビュー (過去 30 日間)
Matt J
Matt J 2024 年 1 月 28 日
コメント済み: Walter Roberson 2024 年 12 月 18 日 5:48
I have the following in my startup.m file,
set(groot,'defaultFigureCreateFcn',@(fig, ~)addToolbarExplorationButtons(fig));
which throws an error when a uifigure is created,
fig = uifigure;
Error using matlab.ui.Figure/set
Functionality not supported with figures created with
the uifigure function.
So, the question becomes, how can I pre-detect whether fig has been created by uifigure() as opposed to figure()? There don't appear to be separate classes reserved for the two,
>> class(figure)
ans =
'matlab.ui.Figure'
>> class(uifigure)
ans =
'matlab.ui.Figure'

採用された回答

Bruno Luong
Bruno Luong 2024 年 1 月 28 日
編集済み: Bruno Luong 2024 年 5 月 5 日
This command returns true for uifigure handle fig
matlab.ui.internal.isUIFigure(fig)
  2 件のコメント
Matt J
Matt J 2024 年 1 月 28 日
It works, which helps a lot. Although, it is peculiar and disquieting that it requires undocumented Matlab.

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

その他の回答 (1 件)

Michael
Michael 2024 年 5 月 5 日
編集済み: Walter Roberson 2024 年 5 月 5 日
So to complete the picture, to get rid of this error:
Functionality not supported with figures created with the uifigure function.
Define this function
function y=makefig(fig);
if ~matlab.ui.internal.isUIFigure(fig)
addToolbarExplorationButtons(fig)
end
and put this in your startup.m
set(groot,'defaultFigureCreateFcn',@(fig,~)makefig(fig));
It would be nice if the Mathworks could do this for us in the next release. Please Guys!
  2 件のコメント
Craig
Craig 2024 年 12 月 18 日 3:32
編集済み: Craig 2024 年 12 月 18 日 3:42
no longer works. @Adam pointed to your solution. However, even using your solution I find that using filterDesigner results in:
Error using filterDesigner (line 79)
Value must be a handle.
Any idea on how to get around that?
Walter Roberson
Walter Roberson 2024 年 12 月 18 日 5:48
I did not post this solution here. @Michael posted the solution here. All I did was reformat Michael's posting to put the code into code blocks.

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

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by