Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122384777
mergeconfig.m
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 17, 13:31
Size
1 KB
Mime Type
text/x-Algol68
Expires
Sat, Jul 19, 13:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27447812
Attached To
R5163 Slepians
mergeconfig.m
View Options
function input = mergeconfig(input, default)
% MERGECONFIG merges the fields of a default structure into an input
% configuration structure
%
% Use as
% output = mergeconfig(input, default)
% Copyright (C) 2009-2012, Robert Oostenveld
%
% $Id: mergeconfig.m 7123 2012-12-06 21:21:38Z roboos $
if isempty(input) && ~isstruct(input)
% ensure that it is an empty struct, not an empty double
input = struct;
end
if isempty(default) && ~isstruct(default)
% ensure that it is an empty struct, not an empty double
default = struct;
end
% merge the input with the fields from default
fieldsused = fieldnames(default);
for i=1:length(fieldsused)
fn = fieldsused{i};
if ~isfield(input, fn) && ~isstruct(default.(fn))
% simply copy the value over
input.(fn) = default.(fn);
elseif ~isfield(input, fn) && isstruct(default.(fn))
% simply copy the substructure over
input.(fn) = default.(fn);
elseif isfield(input, fn) && ~isstruct(default.(fn))
% do not copy it over, keep the original value
elseif isfield(input, fn) && isstruct(default.(fn))
% merge the two substructures
input.(fn) = mergeconfig(input.(fn), default.(fn));
end
end % for all fields
Event Timeline
Log In to Comment