1 ## Copyright (C) 2009, 2010, 2012 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} set (@var{sys})
20 ## @deftypefnx {Function File} set (@var{sys}, @var{"property"}, @var{value}, @dots{})
21 ## @deftypefnx {Function File} {@var{retsys} =} set (@var{sys}, @var{"property"}, @var{value}, @dots{})
22 ## Set or modify properties of LTI objects.
23 ## If no return argument @var{retsys} is specified, the modified LTI object is stored
24 ## in input argument @var{sys}. @command{set} can handle multiple properties in one call:
25 ## @code{set (sys, 'prop1', val1, 'prop2', val2, 'prop3', val3)}.
26 ## @code{set (sys)} prints a list of the object's property names.
29 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
30 ## Created: October 2009
33 function retsys = set (sys, varargin)
35 if (nargin == 1) # set (sys), sys = set (sys)
37 [props, vals] = __property_names__ (sys);
38 nrows = numel (props);
40 str = strjust (strvcat (props), "right");
41 str = horzcat (repmat (" ", nrows, 1), str, repmat (": ", nrows, 1), strvcat (vals));
45 if (nargout != 0) # function sys = set (sys, varargin)
46 retsys = sys; # would lead to unwanted output when using
49 else # set (sys, "prop1", val1, ...), sys = set (sys, "prop1", val1, ...)
51 if (rem (nargin-1, 2))
52 error ("lti: set: properties and values must come in pairs");
57 for k = 1 : 2 : (nargin-1)
58 prop = lower (varargin{k});
62 case {"inname", "inputname"}
63 sys.inname = __adjust_labels__ (val, m);
65 case {"outname", "outputname"}
66 sys.outname = __adjust_labels__ (val, p);
69 if (issample (val, -1))
71 warning ("lti: set: use the editing of property '%s' with caution", prop);
72 warning (" it may lead to corrupted models");
74 error ("lti: set: invalid sampling time");
76 ## TODO: use of c2d, d2c and d2d if tsam changes?
82 error ("lti: set: property 'name' requires a string");
91 error ("lti: set: property 'notes' requires string or cell of strings");
98 sys = __set__ (sys, prop, val);
102 if (nargout == 0) # set (sys, "prop1", val1, ...)
103 assignin ("caller", inputname (1), sys);
104 else # sys = set (sys, "prop1", val1, ...)