Merges two options structures with one having precedence over the other. function opts = mergeOptions(opts1, opts2) input: opts1 and opts2 are two structures. output: opts is a structure containing all fields of opts1 and opts2. Whenever a field is present in both opts1 and opts2, it is the value in opts2 that is kept. The typical usage is to have opts1 contain default options and opts2 contain user-specified options that overwrite the defaults. See also: getGlobalDefaults
0001 function opts = mergeOptions(opts_sub, opts_master) 0002 % Merges two options structures with one having precedence over the other. 0003 % 0004 % function opts = mergeOptions(opts1, opts2) 0005 % 0006 % input: opts1 and opts2 are two structures. 0007 % output: opts is a structure containing all fields of opts1 and opts2. 0008 % Whenever a field is present in both opts1 and opts2, it is the value in 0009 % opts2 that is kept. 0010 % 0011 % The typical usage is to have opts1 contain default options and opts2 0012 % contain user-specified options that overwrite the defaults. 0013 % 0014 % See also: getGlobalDefaults 0015 0016 % This file is part of Manopt: www.manopt.org. 0017 % Original author: Nicolas Boumal, Dec. 30, 2012. 0018 % Contributors: 0019 % Change log: 0020 0021 0022 if isempty(opts_sub) 0023 opts_sub = struct(); 0024 end 0025 if isempty(opts_master) 0026 opts_master = struct(); 0027 end 0028 0029 opts = opts_sub; 0030 fields = fieldnames(opts_master); 0031 for i = 1 : length(fields) 0032 opts.(fields{i}) = opts_master.(fields{i}); 0033 end 0034 0035 end