comparison m-toolbox/classes/@smodel/setValues.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 % SETVALUES Set the property 'values'
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETVALUES Set the property 'values'
5 %
6 % CALL: obj = obj.setValues({1 2});
7 % obj = obj.setValues([1 2]);
8 % obj = obj.setValues(plist('values', {1 2}));
9 %
10 % INPUTS: obj - one ltpda model.
11 % pl - to set the name with a plist specify only one plist with
12 % only one key-word 'values'.
13 %
14 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setValues')">Parameters Description</a>
15 %
16 % VERSION: $Id: setValues.m,v 1.12 2011/04/19 17:26:09 ingo Exp $
17 %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 function varargout = setValues(varargin)
21
22 % Check if this is a call from a class method
23 callerIsMethod = utils.helper.callerIsMethod;
24
25 if callerIsMethod
26 objs = varargin{1};
27
28 if ~iscell(varargin{2})
29 nv = num2cell(varargin{2});
30 else
31 nv = varargin{2};
32 end
33
34 else
35 % Check if this is a call for parameters
36 if utils.helper.isinfocall(varargin{:})
37 varargout{1} = getInfo(varargin{3});
38 return
39 end
40
41 %%% Collect input variable names
42 in_names = cell(size(varargin));
43 for ii = 1:nargin,in_names{ii} = inputname(ii);end
44
45 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
46 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
47
48 %%% If pls contains only one plist with the single key 'values' then set the
49 %%% property with a plist.
50 if length(pls) == 1 && isa(pls, 'plist') && nparams(pls) == 1 && isparam(pls, 'values')
51 rest{1} = find(pls, 'values');
52 end
53
54 if numel(rest) > 1 || isempty(rest)
55 error('### Please specify the values inside a vector or a cell array!');
56 end
57
58 % If 'vals' is an AO or pest then get the 'values' from the y-values.
59 if isa(rest{1}, 'ao')
60 rest{1} = rest{1}.y;
61 elseif isa(rest{1}, 'pest')
62 rest{1} = rest{1}.y;
63 end
64
65 % Conver 'values' into a cell-array
66 if ~iscell(rest{1})
67 nv = num2cell(rest{1});
68 else
69 nv = rest{1};
70 end
71
72 %%% Combine plists
73 pls = combine(pls, plist('values', nv));
74
75 end % callerIsMethod
76
77 %%% decide whether we modify the input smodel object, or create a new one.
78 objs = copy(objs, nargout);
79
80 %%% Set the 'values'
81 for ii = 1:numel(objs)
82 if numel(nv) == numel(objs(ii).params)
83 objs(ii).values = nv;
84 if ~callerIsMethod
85 plh = pls.pset('values', nv);
86 objs(ii).addHistory(getInfo('None'), plh, obj_invars(ii), objs(ii).hist);
87 end
88 else
89 fprintf('Number of parameters of the %dth object is %d, while you provided %d values. Skipping it!\n', ii, numel(objs(ii).params), numel(nv));
90 end
91 end
92
93 %%% Set output
94 if nargout == numel(objs)
95 % List of outputs
96 for ii = 1:numel(objs)
97 varargout{ii} = objs(ii);
98 end
99 else
100 % Single output
101 varargout{1} = objs;
102 end
103 end
104
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 % Local Functions %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 %
111 % FUNCTION: getInfo
112 %
113 % DESCRIPTION: Get Info Object
114 %
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 function ii = getInfo(varargin)
118 if nargin == 1 && strcmpi(varargin{1}, 'None')
119 sets = {};
120 pl = [];
121 else
122 sets = {'Default'};
123 pl = getDefaultPlist;
124 end
125 % Build info object
126 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setValues.m,v 1.12 2011/04/19 17:26:09 ingo Exp $', sets, pl);
127 end
128
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %
131 % FUNCTION: getDefaultPlist
132 %
133 % DESCRIPTION: Get Default Plist
134 %
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 function plout = getDefaultPlist()
138 persistent pl;
139 if exist('pl', 'var')==0 || isempty(pl)
140 pl = buildplist();
141 end
142 plout = pl;
143 end
144
145 function pl = buildplist()
146 pl = plist({'values', 'A cell-array of values, one for each parameter in the model.'}, paramValue.EMPTY_CELL);
147 end
148