1 ## Copyright (C) 2011 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## @deftypefn{Function File} {@var{opt} =} options (@var{"key1"}, @var{value1}, @var{"key2"}, @var{value2}, @dots{})
20 ## Create options struct @var{opt} from a number of key and value pairs.
21 ## For use with order reduction commands.
25 ## @item key, property
26 ## The name of the property.
28 ## The value of the property.
34 ## Struct with fields for each key.
40 ## octave:1> opt = options ("method", "spa", "tol", 1e-6)
43 ## scalar structure containing the fields:
52 ## octave:2> save filename opt
53 ## octave:3> # save the struct 'opt' to file 'filename' for later use
54 ## octave:4> load filename
55 ## octave:5> # load struct 'opt' from file 'filename'
61 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
62 ## Created: November 2011
65 function opt = options (varargin)
72 error ("options: properties and values must come in pairs");
75 ## alternative: opt = struct (varargin{:});
77 key = reshape (varargin(1:2:end-1), [], 1);
78 val = reshape (varargin(2:2:end), [], 1);
80 opt = cell2struct (val, key, 1);
81 opt = orderfields (opt);