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

15 visualizaciones (últimos 30 días)
Matt J
Matt J el 28 de En. de 2024
Comentada: Walter Roberson el 18 de Dic. de 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'

Respuesta aceptada

Bruno Luong
Bruno Luong el 28 de En. de 2024
Editada: Bruno Luong el 5 de Mayo de 2024
This command returns true for uifigure handle fig
matlab.ui.internal.isUIFigure(fig)

Más respuestas (1)

Michael
Michael el 5 de Mayo de 2024
Editada: Walter Roberson el 5 de Mayo de 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 comentarios
Craig
Craig el 18 de Dic. de 2024
Editada: Craig el 18 de Dic. de 2024
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 el 18 de Dic. de 2024
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by