Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/setTrans.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 % SETTRANS sets the 'trans' property of the smodel object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETTRANS sets the 'trans' property of the smodel object. | |
5 % | |
6 % CALL: objs.setTrans(val); | |
7 % objs.setTrans(val1, val2); | |
8 % objs.setTrans(plist('trans', val)); | |
9 % objs = objs.setTrans(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 % - numeric values e.g. 1 | |
15 % - plist with the key 'trans' e.g. plist('trans', {'x1', 'x2'}) | |
16 % - cell-array with the types above | |
17 % | |
18 % REMARK: The 'trans' property can be a matlab express which will be | |
19 % evalulated, or a numeric value. It is meant to specify a | |
20 % scale factor between the user-specified x-values and the | |
21 % user-specified x-variable. | |
22 % | |
23 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setTrans')">Parameters Description</a> | |
24 % | |
25 % VERSION: $Id: setTrans.m,v 1.11 2011/04/28 19:50:57 mauro Exp $ | |
26 % | |
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
28 | |
29 function varargout = setTrans(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 = 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).trans = values; | |
70 if ~callerIsMethod | |
71 plh = pls.pset('trans', 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 'double' | |
96 values = [values {num2str(rest)}]; | |
97 case 'char' | |
98 values = [values {rest}]; | |
99 case 'plist' | |
100 if length(rest) == 1 && isa(rest, 'plist') && isparam(rest, 'trans') | |
101 vals = find(rest, 'trans'); | |
102 values = processValues(values, vals); | |
103 end | |
104 otherwise | |
105 end | |
106 end | |
107 end | |
108 | |
109 %-------------------------------------------------------------------------- | |
110 % Get Info Object | |
111 %-------------------------------------------------------------------------- | |
112 function ii = getInfo(varargin) | |
113 | |
114 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
115 sets = {}; | |
116 pl = []; | |
117 else | |
118 sets = {'Default'}; | |
119 pl = getDefaultPlist(); | |
120 end | |
121 % Build info object | |
122 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setTrans.m,v 1.11 2011/04/28 19:50:57 mauro Exp $', sets, pl); | |
123 end | |
124 | |
125 %-------------------------------------------------------------------------- | |
126 % Get Default Plist | |
127 %-------------------------------------------------------------------------- | |
128 function plout = getDefaultPlist() | |
129 persistent pl; | |
130 if ~exist('pl', 'var') || isempty(pl) | |
131 pl = buildplist(); | |
132 end | |
133 plout = pl; | |
134 end | |
135 | |
136 function pl = buildplist() | |
137 pl = plist({'trans', 'Specify the transformation scale-factor between the x-values and the x-variable.'}, paramValue.EMPTY_CELL); | |
138 end |