Skip to content

Instantly share code, notes, and snippets.

@okomarov
Last active August 29, 2015 14:12
Show Gist options
  • Save okomarov/ab727cdc4cfb45b0e055 to your computer and use it in GitHub Desktop.
Save okomarov/ab727cdc4cfb45b0e055 to your computer and use it in GitHub Desktop.
MATLAB factory defaults to script
%% R2014b
% Retrieve all factory defaults
s = get(0,'factory');
fnames = fieldnames(s);
% groupnames = unique(regexp(fnames, 'factory[A-Z][a-z]+','match','once'));
% Select those of interest
groupnames = {
'factoryAnimatedline'
'factoryAnnotationpane'
'factoryArea'
'factoryArrowshape'
'factoryAxes'
'factoryBar'
'factoryColorbar'
'factoryContour'
'factoryDoubleendarrowshape'
'factoryEllipseshape'
'factoryErrorbar'
'factoryFigure'
'factoryHggroup'
'factoryHgjavacomponent'
'factoryHgtransform'
'factoryHistogram'
'factoryImage'
'factoryLegend'
'factoryLight'
'factoryLine'
'factoryLineshape'
'factoryPatch'
'factoryQuiver'
'factoryRectangle'
'factoryRectangleshape'
'factoryRoot'
'factoryScatter'
'factoryStair'
'factoryStem'
'factorySurface'
'factoryText'
'factoryTextarrowshape'
'factoryTextboxshape'
% 'factoryUibuttongroup'
% 'factoryUicontainer'
% 'factoryUicontextmenu'
% 'factoryUicontrol'
% 'factoryUiflowcontainer'
% 'factoryUigridcontainer'
% 'factoryUimenu'
% 'factoryUipanel'
% 'factoryUipushtool'
% 'factoryUisplittool'
% 'factoryUitab'
% 'factoryUitabgroup'
% 'factoryUitable'
% 'factoryUitogglesplittool'
% 'factoryUitoggletool'
% 'factoryUitoolbar'
};
% Keep only groups of interest
idx = cellfun(@(s) strncmp(s,fnames,numel(s)),groupnames,'un',0)';
idx = sum([idx{:}],2) > 0;
% Flag fields which are struct themselves or other funky classes
idx = ~idx | structfun(@(x) isstruct(x) | isa(x, 'matlab.graphics.GraphicsPlaceholder') | isa(x,'matlab.mixin.Heterogeneous'),s);
% Flag the easter egg image http://uk.mathworks.com/matlabcentral/answers/2001#answer_3188
idx = idx | strcmp(fnames, 'factoryImageCData');
% Drop
s = rmfield(s,fnames(idx));
% Replace 1x0 empty arrays with [] or ''
fnames = fieldnames(s);
for ii = 1:numel(fnames)
f = s.(fnames{ii});
if isempty(f)
if ischar(ischar(f))
s.(fnames{ii}) = '';
elseif isnumeric(f)
s.(fnames{ii}) = [];
end
end
end
matlab.io.saveVariablesToScript('factoryDefaultsR2014b','s', 'MaximumArraySize',4096, 'MaximumTextWidth',100)
% -------------------------------------------------------------------------------------------------------------
%% R2014a
% Retrieve all factory defaults
set(0,'HideUndocumented','off')
s = get(0,'factory');
fnames = fieldnames(s);
% groupnames = unique(regexp(fnames, 'factory[A-Z][a-z]+','match','once'));
% Select those of interest
groupnames = {
'factoryAxes'
'factoryFigure'
'factoryHggroup'
'factoryHgjavacomponent'
'factoryHgtransform'
'factoryImage'
'factoryLight'
'factoryLine'
'factoryPatch'
'factoryRectangle'
'factoryRoot'
'factorySurface'
'factoryText'
% 'factoryUicontainer'
% 'factoryUicontextmenu'
% 'factoryUicontrol'
% 'factoryUiflowcontainer'
% 'factoryUigridcontainer'
% 'factoryUimenu'
% 'factoryUipanel'
% 'factoryUipushtool'
% 'factoryUisplittool'
% 'factoryUitable'
% 'factoryUitogglesplittool'
% 'factoryUitoggletool'
% 'factoryUitoolbar'
};
% Keep only groups of interest
idx = cellfun(@(s) strncmp(s,fnames,numel(s)),groupnames,'un',0)';
idx = sum([idx{:}],2) > 0;
% Flag fields which are struct themselves
idx = ~idx | structfun(@isstruct,s);
% Flag the easter egg image http://uk.mathworks.com/matlabcentral/answers/2001#answer_3188
idx = idx | strcmp(fnames, 'factoryImageCData');
% Drop
s = rmfield(s,fnames(idx));
% Replace 1x0 empty arrays with [] or ''
fnames = fieldnames(s);
for ii = 1:numel(fnames)
f = s.(fnames{ii});
if isempty(f)
if ischar(ischar(f))
s.(fnames{ii}) = '';
elseif isnumeric(f)
s.(fnames{ii}) = [];
end
end
end
matlab.io.saveVariablesToScript('factoryDefaultsR2014a','s', 'MaximumArraySize',4096, 'MaximumTextWidth',100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment