Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/setXunits.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 % SETXUNITS sets the 'xunits' property of the smodel object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETXUNITS sets the 'xunits' property of the smodel object. | |
5 % | |
6 % CALL: objs.setXunits(val); | |
7 % objs.setXunits(plist('xunits', val)); | |
8 % objs = objs.setXunits(val); | |
9 % | |
10 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them. | |
11 % val: Can be one of the following types: | |
12 % - unit-string | |
13 % - unit-object | |
14 % - plist with the key 'xunits' | |
15 % - cell with the types above | |
16 % | |
17 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setXunits')">Parameters Description</a> | |
18 % | |
19 % VERSION: $Id: setXunits.m,v 1.13 2011/05/05 20:50:43 mauro Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function varargout = setXunits(varargin) | |
24 | |
25 % Check if this is a call from a class method | |
26 callerIsMethod = utils.helper.callerIsMethod; | |
27 | |
28 if callerIsMethod | |
29 sm = varargin{1}; | |
30 values = varargin(2:end); | |
31 | |
32 else | |
33 % Check if this is a call for parameters | |
34 if utils.helper.isinfocall(varargin{:}) | |
35 varargout{1} = getInfo(varargin{3}); | |
36 return | |
37 end | |
38 | |
39 import utils.const.* | |
40 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
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 % Collect all smodel objects | |
47 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
48 pls = utils.helper.collect_objects(rest(:), 'plist'); | |
49 | |
50 % Get values for the smodel objects | |
51 values = processValues([], rest); | |
52 | |
53 % Combine input plists and default PLIST | |
54 pls = combine(pls, getDefaultPlist()); | |
55 | |
56 end % callerIsMethod | |
57 | |
58 % Decide on a deep copy or a modify | |
59 sm = copy(sm, nargout); | |
60 | |
61 % Loop over smodel objects | |
62 for jj = 1:numel(sm) | |
63 sm(jj).xunits = values; | |
64 if ~callerIsMethod | |
65 plh = pls.pset('xunits', values); | |
66 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), sm(jj).hist); | |
67 end | |
68 end | |
69 | |
70 % Set output | |
71 varargout = utils.helper.setoutputs(nargout, sm); | |
72 end | |
73 | |
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
75 % Local Functions % | |
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
77 %-------------------------------------------------------------------------- | |
78 % Process Values | |
79 %-------------------------------------------------------------------------- | |
80 function values = processValues(values, rest) | |
81 | |
82 switch class(rest) | |
83 case 'char' | |
84 values = [values unit(rest)]; | |
85 case 'unit' | |
86 values = [values reshape(rest, 1, [])]; | |
87 case 'cell' | |
88 for ii = 1:numel(rest) | |
89 values = processValues(values, rest{ii}); | |
90 end | |
91 case 'plist' | |
92 if length(rest) == 1 && isa(rest, 'plist') && isparam(rest, 'xunits') | |
93 vals = find(rest, 'xunits'); | |
94 values = processValues(values, vals); | |
95 end | |
96 otherwise | |
97 error('LTPDA:err:UnsupportedClass', 'Unsupported container ''%s'' for the [Xunits] property', class(rest)); | |
98 end | |
99 end | |
100 | |
101 | |
102 %-------------------------------------------------------------------------- | |
103 % Get Info Object | |
104 %-------------------------------------------------------------------------- | |
105 function ii = getInfo(varargin) | |
106 | |
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, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setXunits.m,v 1.13 2011/05/05 20:50:43 mauro Exp $', sets, pl); | |
116 end | |
117 | |
118 %-------------------------------------------------------------------------- | |
119 % Get Default Plist | |
120 %-------------------------------------------------------------------------- | |
121 function plout = getDefaultPlist() | |
122 persistent pl; | |
123 if ~exist('pl', 'var') || isempty(pl) | |
124 pl = buildplist(); | |
125 end | |
126 plout = pl; | |
127 end | |
128 | |
129 function pl = buildplist() | |
130 pl = plist({'xunits', 'The units for the X variable.'}, paramValue.EMPTY_STRING); | |
131 end |