How to change figure properties for all figures in MATLAB?

조회 수: 69 (최근 30일)
Benjamin
Benjamin 2020년 12월 10일
답변: Steven Lord 2020년 12월 10일
Dear experts,
If in a MATLAB program there be plenty of figures, is it possible to specify a figure property (e.g. grid on) for all figures, instead of writing it after each figure command?
Regards,
Benjamin

답변 (2개)

Rik
Rik 2020년 12월 10일
set(groot,'defaultFigureCreateFcn',@(fig,~)SomeFunction(fig))

Steven Lord
Steven Lord 2020년 12월 10일
You can set default property values for graphics objects that are created in the future. Changing the defaults will not change the property values for existing graphics objects (even if they used the default values for those properties when they were created.) For that you probably want to use findobj or findall to obtain the handles to those graphics objects (if you don't already have them) and change those property values. Run the commands in the example below one section at a time.
f1 = figure;
f2 = figure;
set(groot, 'DefaultFigureColor', 'r') % figures f1 and f2 do not change color
f3 = figure; % f3 is a different color than f1 and f2
allfigs = findall(groot, 'type', 'figure');
set(allfigs, 'Color', 'c'); % f1, f2, and f3 each become cyan
set([f2, f3], 'Color', 'k') % f2 and f3 become black, f1 remains cyan

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by