How to change figure properties for all figures in MATLAB?

69 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Rik
Rik il 10 Dic 2020
set(groot,'defaultFigureCreateFcn',@(fig,~)SomeFunction(fig))

Steven Lord
Steven Lord il 10 Dic 2020
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

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by