Effacer les filtres
Effacer les filtres

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

8 vues (au cours des 30 derniers jours)
Matt J
Matt J le 28 Jan 2024
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!

Catégories

En savoir plus sur Develop uifigure-Based Apps 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