comparison m-toolbox/classes/@smodel/setXvar.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SETXVAR sets the 'xvar' property of the smodel object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETXVAR sets the 'xvar' property of the smodel object.
5 %
6 % CALL: objs.setXvar(val);
7 % objs.setXvar(val1, val2);
8 % objs.setXvar(plist('xvar', val));
9 % objs = objs.setXvar(val);
10 %
11 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them.
12 % val: Can be any of the following types:
13 % - string e.g. 'x1'
14 % - plist with the key 'xvar' e.g. plist('xvar', {'x1', 'x2'})
15 % - cell-array with the types above
16 %
17 % REMARK: The x-variable defines later the type of the data object.
18 % 't': AO with time-series data
19 % 'f': AO with frequency-series data
20 % 'w': AO with frequency-series data
21 % all other: AO with xy data
22 %
23 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setXvar')">Parameters Description</a>
24 %
25 % VERSION: $Id: setXvar.m,v 1.12 2011/08/16 06:06:05 hewitson Exp $
26 %
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
29 function varargout = setXvar(varargin)
30
31 % Check if this is a call from a class method
32 callerIsMethod = utils.helper.callerIsMethod;
33
34 if callerIsMethod
35 sm = varargin{1};
36 values = processValues({}, varargin(2:end));
37
38 else
39 % Check if this is a call for parameters
40 if utils.helper.isinfocall(varargin{:})
41 varargout{1} = getInfo(varargin{3});
42 return
43 end
44
45 import utils.const.*
46 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
47
48 % Collect input variable names
49 in_names = cell(size(varargin));
50 for ii = 1:nargin,in_names{ii} = inputname(ii);end
51
52 % Collect all smodel objects
53 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
54 pls = utils.helper.collect_objects(rest(:), 'plist');
55
56 % Combine input plists and default PLIST
57 pls = combine(pls, getDefaultPlist());
58
59 % Get values for the smodel objects
60 values = processValues({}, rest);
61
62 end % callerIsMethod
63
64 % Decide on a deep copy or a modify
65 sm = copy(sm, nargout);
66
67 % Loop over smodel objects
68 for jj = 1:numel(sm)
69 sm(jj).xvar = values;
70 if ~callerIsMethod
71 plh = pls.pset('xvar', values);
72 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), sm(jj).hist);
73 end
74 end
75
76 % Set output
77 varargout = utils.helper.setoutputs(nargout, sm);
78 end
79
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % Local Functions %
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 function values = processValues(values, rest)
85 if ~isempty(rest)
86 switch class(rest)
87 case 'cell'
88 if iscellstr(rest)
89 values = [values rest];
90 else
91 for ii = 1:numel(rest);
92 values = processValues(values, rest{ii});
93 end
94 end
95 case 'char'
96 values = [values {rest}];
97 case 'plist'
98 if length(rest) == 1 && isa(rest, 'plist') && isparam(rest, 'xvar')
99 vals = find(rest, 'xvar');
100 values = processValues(values, vals);
101 end
102 otherwise
103 end
104 end
105 end
106
107 %--------------------------------------------------------------------------
108 % Get Info Object
109 %--------------------------------------------------------------------------
110 function ii = getInfo(varargin)
111
112 if nargin == 1 && strcmpi(varargin{1}, 'None')
113 sets = {};
114 pl = [];
115 else
116 sets = {'Default'};
117 pl = getDefaultPlist();
118 end
119 % Build info object
120 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setXvar.m,v 1.12 2011/08/16 06:06:05 hewitson Exp $', sets, pl);
121 end
122
123 %--------------------------------------------------------------------------
124 % Get Default Plist
125 %--------------------------------------------------------------------------
126 function plout = getDefaultPlist()
127 persistent pl;
128 if ~exist('pl', 'var') || isempty(pl)
129 pl = buildplist();
130 end
131 plout = pl;
132 end
133
134 function pl = buildplist()
135 pl = plist({'xvar', 'Specify the X-dependent variable in the model.'}, paramValue.EMPTY_CELL);
136 end