How to detect whether a figure is created by uifigure()
조회 수: 22 (최근 30일)
이전 댓글 표시
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
채택된 답변
Bruno Luong
2024년 1월 28일
편집: Bruno Luong
2024년 5월 5일
This command returns true for uifigure handle fig
matlab.ui.internal.isUIFigure(fig)
댓글 수: 2
추가 답변 (1개)
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!