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

32 vues (au cours des 30 derniers jours)
Matt J
Matt J le 28 Jan 2024
Commenté : Walter Roberson le 18 Déc 2024 à 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'

Réponse acceptée

Bruno Luong
Bruno Luong le 28 Jan 2024
Modifié(e) : Bruno Luong le 5 Mai 2024
This command returns true for uifigure handle fig
matlab.ui.internal.isUIFigure(fig)
  2 commentaires
Matt J
Matt J le 28 Jan 2024
It works, which helps a lot. Although, it is peculiar and disquieting that it requires undocumented Matlab.

Connectez-vous pour commenter.

Plus de réponses (1)

Michael
Michael le 5 Mai 2024
Modifié(e) : Walter Roberson le 5 Mai 2024
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 commentaires
Craig
Craig le 18 Déc 2024 à 3:32
Modifié(e) : Craig le 18 Déc 2024 à 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 le 18 Déc 2024 à 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by