Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/setAliasNames.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 % SETALIASNAMES Set the property 'aliasNames' | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETALIASNAMES Set the property 'aliasNames' | |
5 % | |
6 % CALL: obj = obj.setAliasNames({'a', 'b'}); | |
7 % obj = obj.setAliasNames(plist('aliasNames', {'a', 'b'})); | |
8 % | |
9 % INPUTS: obj - one ltpda model. | |
10 % pl - to set the name with a plist specify only one plist with | |
11 % only the key-word 'aliasNames'. | |
12 % | |
13 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setAliasNames')">Parameters Description</a> | |
14 % | |
15 % VERSION: $Id: setAliasNames.m,v 1.6 2011/04/28 19:50:57 mauro Exp $ | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 function varargout = setAliasNames(varargin) | |
20 | |
21 % Check if this is a call from a class method | |
22 callerIsMethod = utils.helper.callerIsMethod; | |
23 | |
24 if callerIsMethod | |
25 sm = varargin{1}; | |
26 values = varargin(2:end); | |
27 | |
28 else | |
29 % Check if this is a call for parameters | |
30 if utils.helper.isinfocall(varargin{:}) | |
31 varargout{1} = getInfo(varargin{3}); | |
32 return | |
33 end | |
34 | |
35 import utils.const.* | |
36 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
37 | |
38 % Collect input variable names | |
39 in_names = cell(size(varargin)); | |
40 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
41 | |
42 % Collect all smodel objects | |
43 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
44 pls = utils.helper.collect_objects(rest(:), 'plist'); | |
45 | |
46 % Combine input plists and default PLIST | |
47 pls = combine(pls, getDefaultPlist()); | |
48 | |
49 % Get values for the smodel objects | |
50 values = processValues({}, rest); | |
51 | |
52 end % callerIsMethod | |
53 | |
54 % Decide on a deep copy or a modify | |
55 sm = copy(sm, nargout); | |
56 | |
57 % Loop over smodel objects | |
58 for jj = 1:numel(sm) | |
59 sm(jj).aliasNames = values; | |
60 if ~callerIsMethod | |
61 plh = pls.pset('aliasNames', values); | |
62 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), sm(jj).hist); | |
63 end | |
64 end | |
65 | |
66 % Set output | |
67 varargout = utils.helper.setoutputs(nargout, sm); | |
68 | |
69 end | |
70 | |
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
72 % Local Functions % | |
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
74 | |
75 function values = processValues(values, rest) | |
76 if ~isempty(rest) | |
77 switch class(rest) | |
78 case 'cell' | |
79 if iscellstr(rest) | |
80 values = [values rest]; | |
81 else | |
82 for ii = 1:numel(rest); | |
83 values = processValues(values, rest{ii}); | |
84 end | |
85 end | |
86 case 'char' | |
87 values = [values {rest}]; | |
88 case 'plist' | |
89 if length(rest) == 1 && isa(rest, 'plist') && isparam(rest, 'xvar') | |
90 vals = find(rest, 'xvar'); | |
91 values = processValues(values, vals); | |
92 end | |
93 otherwise | |
94 end | |
95 end | |
96 end | |
97 | |
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
99 % | |
100 % FUNCTION: getInfo | |
101 % | |
102 % DESCRIPTION: Get Info Object | |
103 % | |
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
105 | |
106 function ii = getInfo(varargin) | |
107 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
108 sets = {}; | |
109 pl = []; | |
110 else | |
111 sets = {'Default'}; | |
112 pl = getDefaultPlist(); | |
113 end | |
114 % Build info object | |
115 ii = minfo(mfilename, 'smodel', 'ltpda', utils.const.categories.helper, '$Id: setAliasNames.m,v 1.6 2011/04/28 19:50:57 mauro Exp $', sets, pl); | |
116 end | |
117 | |
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
119 % | |
120 % FUNCTION: getDefaultPlist | |
121 % | |
122 % DESCRIPTION: Get Default Plist | |
123 % | |
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
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(); | |
136 | |
137 % Params | |
138 p = param({'aliasNames', 'A cell-array of alias names.'}, paramValue.EMPTY_CELL); | |
139 pl.append(p); | |
140 end | |
141 |