comparison m-toolbox/classes/@smodel/setYunits.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 % SETYUNITS sets the 'yunits' property of the smodel object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETYUNITS sets the 'yunits' property of the smodel object.
5 %
6 % CALL: objs.setYunits(val);
7 % objs.setYunits(val1, val2);
8 % objs.setYunits(plist('yunits', val));
9 % objs = objs.setYunits(val);
10 %
11 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them.
12 % val:
13 % 1. Single string e.g. 'Hz'
14 % Each smodel object in objs get this value.
15 % 2. Single string in a cell-array e.g. {'Hz'}
16 % Each smodel object in objs get this value.
17 % 3. cell-array with the same number of strings as in objs
18 % e.g. {'Hz', 'V', 's'} and 3 smodel object in objs
19 % Each smodel object in objs get its corresponding
20 % value from the cell-array
21 %
22 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setYunits')">Parameters Description</a>
23 %
24 % VERSION: $Id: setYunits.m,v 1.12 2011/09/16 05:03:21 hewitson Exp $
25 %
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 function varargout = setYunits(varargin)
29
30 % Check if this is a call from a class method
31 callerIsMethod = utils.helper.callerIsMethod;
32 if callerIsMethod
33 sm = varargin{1};
34 values = varargin(2:end);
35
36 else
37 % Check if this is a call for parameters
38 if utils.helper.isinfocall(varargin{:})
39 varargout{1} = getInfo(varargin{3});
40 return
41 end
42
43 import utils.const.*
44 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
45
46 % Collect input variable names
47 in_names = cell(size(varargin));
48 for ii = 1:nargin,in_names{ii} = inputname(ii);end
49
50 % Collect all smodel objects
51 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
52 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
53
54 % Define property name
55 pName = 'yunits';
56
57 % Get values for the smodel objects
58 [sm, values] = processSetterValues(sm, pls, rest, pName);
59
60 % Combine input plists and default PLIST
61 pls = combine(pls, getDefaultPlist());
62
63 end % callerIsMethod
64
65 % Decide on a deep copy or a modify
66 sm = copy(sm, nargout);
67
68 % Loop over smodel objects
69 for jj = 1:numel(sm)
70 sm(jj).yunits = values{jj};
71 if ~callerIsMethod
72 plh = pls.pset(pName, values{jj});
73 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), sm(jj).hist);
74 end
75 end
76
77 % Set output
78 varargout = utils.helper.setoutputs(nargout, sm);
79
80 end
81
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % Local Functions %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %--------------------------------------------------------------------------
86 % Get Info Object
87 %--------------------------------------------------------------------------
88 function ii = getInfo(varargin)
89
90 if nargin == 1 && strcmpi(varargin{1}, 'None')
91 sets = {};
92 pl = [];
93 else
94 sets = {'Default'};
95 pl = getDefaultPlist();
96 end
97 % Build info object
98 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setYunits.m,v 1.12 2011/09/16 05:03:21 hewitson Exp $', sets, pl);
99 end
100
101 %--------------------------------------------------------------------------
102 % Get Default Plist
103 %--------------------------------------------------------------------------
104 function plout = getDefaultPlist()
105 persistent pl;
106 if ~exist('pl', 'var') || isempty(pl)
107 pl = buildplist();
108 end
109 plout = pl;
110 end
111
112 function pl = buildplist()
113 pl = plist({'yunits', 'The units for the Y variable.'}, paramValue.EMPTY_STRING);
114 end