How to detect whether a figure is created by uifigure()
21 views (last 30 days)
Show older comments
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'
0 Comments
Accepted Answer
Bruno Luong
on 28 Jan 2024
Edited: Bruno Luong
on 5 May 2024
This command returns true for uifigure handle fig
matlab.ui.internal.isUIFigure(fig)
2 Comments
More Answers (1)
Michael
on 5 May 2024
Edited: Walter Roberson
on 5 May 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 Comments
Craig
on 18 Dec 2024
Edited: Craig
on 18 Dec 2024
Hello @Walter Roberson, I found that the old solution at: https://www.mathworks.com/matlabcentral/answers/419036-what-happened-to-the-figure-toolbar-why-is-it-an-axes-toolbar-how-can-i-put-the-buttons-back
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
on 18 Dec 2024
See Also
Categories
Find more on Specifying Target for Graphics Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!