comparison m-toolbox/classes/@smodel/setXvals.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 % SETXVALS sets the 'xvals' property of the smodel object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETXVALS sets the 'xvals' property of the smodel object.
5 %
6 % CALL: objs.setXvals(val);
7 % objs.setXvals(plist('xvals', val));
8 % objs = objs.setXvals(val);
9 %
10 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them.
11 % val: Val can be any of the following types:
12 % - double-vector
13 % - analysis object(s)
14 % - plist with the key 'xvals'
15 % - cell array with the value above
16 % All objects in 'objs' get 'val' as the 'xvals'
17 %
18 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setXvals')">Parameters Description</a>
19 %
20 % VERSION: $Id: setXvals.m,v 1.12 2011/04/28 19:50:57 mauro Exp $
21 %
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24 function varargout = setXvals(varargin)
25
26 % Check if this is a call from a class method
27 callerIsMethod = utils.helper.callerIsMethod;
28
29 if callerIsMethod
30 sm = varargin{1};
31 values = varargin{2};
32
33 else
34 % Check if this is a call for parameters
35 if utils.helper.isinfocall(varargin{:})
36 varargout{1} = getInfo(varargin{3});
37 return
38 end
39
40 import utils.const.*
41 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
42
43 % Collect input variable names
44 in_names = cell(size(varargin));
45 for ii = 1:nargin,in_names{ii} = inputname(ii);end
46
47 % Collect all smodel objects
48 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
49 [pls, dummy, onlyAoRest] = utils.helper.collect_objects(rest(:), 'plist');
50 [aos, dummy, onlyAoRest] = utils.helper.collect_objects(onlyAoRest(:), 'ao');
51
52 values = {};
53 inhists = [];
54 % If pls contains only one plist with the single key of the property name
55 % then set the property with a plist.
56
57 % Combine input plists and default PLIST
58 pls = combine(pls, getDefaultPlist());
59
60 % Special behaviour for the history if the user uses only AOs for the xvals
61 if ~isempty(aos) && isempty(onlyAoRest)
62 inhists = [aos(:).hist];
63 values = processValues(values, pls, aos);
64 else
65 values = processValues(values, pls, rest);
66 end
67
68 % Check if the x-values are empty
69 if isempty(values)
70 error('### Please specify at least one input for ''xvals''');
71 end
72 % Make sure that all x-values have the same length
73 if any(diff(cellfun(@length, values)) ~= 0)
74 error('### The xvals must have the same length. But they have the length %s', mat2str(cellfun(@length, values)));
75 end
76
77 end % callerIsMethod
78
79 % Decide on a deep copy or a modify
80 sm = copy(sm, nargout);
81
82 % Loop over smodel objects
83 for jj = 1:numel(sm)
84 sm(jj).xvals = values;
85 if ~callerIsMethod
86 if isempty(inhists)
87 % Add the values only to the history-plist if the user doesn't use
88 % AOs for the xvals.
89 plh = pls.pset('xvals', values);
90 else
91 plh = pls;
92 end
93 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), [sm(jj).hist, inhists]);
94 end
95 end
96
97 % Set output
98 varargout = utils.helper.setoutputs(nargout, sm);
99 end
100
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 % Local Functions %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105 function values = processValues(values, dpl, rest)
106
107 if ~isempty(rest)
108 switch class(rest)
109 case 'cell'
110 for ii = 1:numel(rest);
111 values = processValues(values, dpl, rest{ii});
112 end
113 case 'double'
114 values = [values {rest}];
115 case 'ao'
116 ax = dpl.find('axis');
117 for ii = 1:numel(rest)
118 values = [values {rest(ii).(ax)}];
119 end
120 case 'plist'
121 if length(rest) == 1 && isa(rest, 'plist') && isparam(rest, 'xvals')
122 vals = find(rest, 'xvals');
123 values = processValues(values, dpl, vals);
124 end
125 otherwise
126 end
127 end
128 end
129
130 %--------------------------------------------------------------------------
131 % Get Info Object
132 %--------------------------------------------------------------------------
133 function ii = getInfo(varargin)
134
135 if nargin == 1 && strcmpi(varargin{1}, 'None')
136 sets = {};
137 pl = [];
138 else
139 sets = {'Default'};
140 pl = getDefaultPlist();
141 end
142 % Build info object
143 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setXvals.m,v 1.12 2011/04/28 19:50:57 mauro Exp $', sets, pl);
144 end
145
146 %--------------------------------------------------------------------------
147 % Get Default Plist
148 %--------------------------------------------------------------------------
149 function plout = getDefaultPlist()
150 persistent pl;
151 if ~exist('pl', 'var') || isempty(pl)
152 pl = buildplist();
153 end
154 plout = pl;
155 end
156
157 function pl = buildplist()
158 pl = plist();
159
160 % xvals
161 p = param({'xvals', 'A vector of values for the X variables.'}, paramValue.EMPTY_CELL);
162 pl.append(p);
163
164 % axis
165 p = param({'axis', 'Chose the axis where to take the data from the ao.'}, {1, {'y', 'x', 'z'}, paramValue.OPTIONAL});
166 pl.append(p);
167
168 end