get(0,'default') does not list all default properties

11 次查看(过去 30 天)
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!

采纳的回答

Jan
Jan 2012-9-16
编辑:Jan 2012-9-16
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.

更多回答(1 个)

Matt Fig
Matt Fig 2012-9-17
编辑:Matt Fig 2012-9-17
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
  1 个评论
John Lunzer
John Lunzer 2012-9-17
This my good friend, is absolutely beautiful and a huge part of what I was looking for!
One thing I've been particularly interested in lately is the properties of the data cursor. I usually get these through:
cursorMode = datacursormode(gcf)
cursorMode.CurrentDataCursor.get
And then set any properties I want by placing set() commands in a custom cursor update function. I do this because these properties only appear once the data cursor has been placed on the plot. This method isn't perfect and I have issues when I use sub plots.
My follow up question: is there a way to place the datacursor on a plot automatically (without the user clicking) and then is there a way to integrate that into this awesome function?
Thanks for your wonderful help!

请先登录,再进行评论。

类别

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