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