get(0,'default') does not list all default properties
11 views (last 30 days)
Show older comments
Here is my output in Matlab2012a for the following command:
>> get(0,'default')
ans =
defaultFigurePosition: [560 528 560 420]
defaultTextColor: [0 0 0]
defaultAxesXColor: [0 0 0]
defaultAxesYColor: [0 0 0]
defaultAxesZColor: [0 0 0]
defaultPatchFaceColor: [0 0 0]
defaultPatchEdgeColor: [0 0 0]
defaultLineColor: [0 0 0]
defaultFigureInvertHardcopy: 'on'
defaultFigureColor: [0.8000 0.8000 0.8000]
defaultAxesColor: [1 1 1]
defaultAxesColorOrder: [7x3 double]
defaultFigureColormap: [64x3 double]
defaultSurfaceEdgeColor: [0 0 0]
I know there are more default values than this as I can access them individually if I already know them (DefaultLineLineWidth, DefaultLineLineStyle, etc.) As far as I can tell this list should be massive. That command is the most common suggestion for listing default values.
Any suggestions on why it doesn't list all default values (related to figures/axes/plot/etc)? Thanks!
0 Comments
Accepted Answer
Jan
on 16 Sep 2012
Edited: Jan
on 16 Sep 2012
The default values precede the factory values. Default values found by get(0, 'default') have been set in the function matlabrc or anywhere else. The missing defaults use the factory settings. See doc: setting-default-property-values.
get(0, 'default')
% Does not contain 'defaultLineColor'
get(0, 'defaultLineColor')
% [0,0,0]
set(0, 'defaultLineColor', [1, 0, 0])
get(0, 'default')
% Does contain 'defaultLineColor'
% Set the value to the factory settings:
set(0, 'defaultLineColor', 'factory')
get(0, 'defaultLineColor')
% [0,0,0]
% Remove the default, such that the factory is used:
set(0, 'defaultLineColor', 'remove')
The magic strings 'default', 'remove', and 'factory' are used to control the default values. A sad side-effect is, that these strings cannot be used as values of properties directly:
figure;
uicontrol('String', 'default');
This does not show 'default' in a button, but an empty string! You have to use this:
uicontrol('String', '\default');
This is obviously a bad design from the very early days of Matlab kept for backward compatibility. Of course the special commands should be the ones started with a backslash.
2 Comments
More Answers (1)
Matt Fig
on 17 Sep 2012
Edited: Matt Fig
on 17 Sep 2012
Here is a silly little function to get all of those defaults listed. You could modify this to produce more or less by manipulating the cell array HC, and of course instantiating an instance of any object in named in HC. Also, one could modify this to allow a handle to be passed in, then return the defaults for only that type of object.
function S = defaultprops()
% Returns default property values for common HG objects.
% Only returns those properties who have non-empty values.
% Author: Matt Fig
HC = {'figure','axes','line','text','patch','uicontrol',...
'uicontextmenu','uimenu','image','surface','light',...
'rectangle'};
warning off %#ok
onof = get(0,'showhidden');
set(0,'showhidden','on');
% Create the objects.
F = figure('visible','off','tag','propfig');
plot(1:10);
text;
uicontrol;
patch([0 0],[0 0],'r');
image;
rectangle;
surface;
uicontextmenu;
uimenu;
light;
for ii = 1:length(HC)
prp = get(findobj(F,'type',HC{ii}));
fn = fieldnames(prp);
for jj = 1:length(fn)
try
dfp = get(0,['default',HC{ii},fn{jj}]);
if ~isempty(dfp) % Remove to return all settables.
S.(HC{ii}).(fn{jj}) = dfp;
end
catch %#ok
end
end
end
close(F)
set(0,'showhidden',onof)
warning on %#ok
See Also
Categories
Find more on Graphics Object Properties 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!