Mercurial > hg > octave-lyh
comparison scripts/optimization/optimset.m @ 11121:134d357e1c03
optimization/optimset.m: Use cell2struct instead of struct to handle cell arrays as options
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 20 Oct 2010 20:51:33 -0400 |
parents | be55736a0783 |
children | 30f54b3b9953 |
comparison
equal
deleted
inserted
replaced
11120:a44f979a35ce | 11121:134d357e1c03 |
---|---|
74 old.(key) = val; | 74 old.(key) = val; |
75 endfor | 75 endfor |
76 retval = old; | 76 retval = old; |
77 elseif (rem (nargs, 2) && isstruct (varargin{1})) | 77 elseif (rem (nargs, 2) && isstruct (varargin{1})) |
78 ## Set values in old from name/value pairs. | 78 ## Set values in old from name/value pairs. |
79 retval = optimset (varargin{1}, struct (varargin{2:end})); | 79 pairs = reshape (varargin(2:end), 2, []); |
80 retval = optimset (varargin{1}, cell2struct (pairs(2, :), pairs(1, :), 2)); | |
80 elseif (rem (nargs, 2) == 0) | 81 elseif (rem (nargs, 2) == 0) |
81 ## Create struct. Default values are replaced by those specified by | 82 ## Create struct. Default values are replaced by those specified by |
82 ## name/value pairs. | 83 ## name/value pairs. |
83 retval = optimset (struct (), struct (varargin{:})); | 84 pairs = reshape (varargin, 2, []); |
85 retval = optimset (struct (), cell2struct (pairs(2, :), pairs(1, :), 2)); | |
84 else | 86 else |
85 print_usage (); | 87 print_usage (); |
86 endif | 88 endif |
87 | 89 |
88 endfunction | 90 endfunction |