Home > manopt > core > mergeOptions.m

mergeOptions

PURPOSE ^

Merges two options structures with one having precedence over the other.

SYNOPSIS ^

function opts = mergeOptions(opts1, opts2)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opts = mergeOptions(opts1, opts2)
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(opts1)
0023         opts1 = struct();
0024     end
0025     if isempty(opts2)
0026         opts2 = struct();
0027     end
0028 
0029     opts = opts1;
0030     fields = fieldnames(opts2);
0031     for i = 1 : length(fields)
0032         opts.(fields{i}) = opts2.(fields{i});
0033     end
0034     
0035 end

Generated on Fri 08-Sep-2017 12:43:19 by m2html © 2005