Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/setToffset.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 % SETTOFFSET sets the 'toffset' property of the ao with tsdata | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETTOFFSET sets the 'toffset' property of the ao with tsdata | |
5 % | |
6 % CALL: objs.setToffset(val); | |
7 % objs.setToffset(plist('toffset', val)); | |
8 % objs = objs.setToffset(val); | |
9 % | |
10 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them. | |
11 % val: In seconds | |
12 % 1. Single value e.g. [2] | |
13 % Each AO in objs get this value. | |
14 % 2. Single value in a cell-array e.g. {12.1} | |
15 % Each AO in objs get this value. | |
16 % 3. cell-array with the same number of values as in objs | |
17 % e.g. {7, 5, 12.2} and 3 AOs in objs | |
18 % Each AO in objs get its corresponding value from the | |
19 % cell-array | |
20 % | |
21 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'setToffset')">Parameters Description</a> | |
22 % | |
23 % VERSION: $Id: setToffset.m,v 1.3 2011/09/17 03:09:26 hewitson Exp $ | |
24 % | |
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
26 | |
27 function varargout = setToffset(varargin) | |
28 | |
29 % Check if this is a call from a class method | |
30 callerIsMethod = utils.helper.callerIsMethod; | |
31 | |
32 if callerIsMethod | |
33 as = varargin{1}; | |
34 toffset = varargin(2); | |
35 | |
36 % Replicate the values | |
37 values = cell(size(as)); | |
38 values(:) = toffset; | |
39 | |
40 else | |
41 % Check if this is a call for parameters | |
42 if utils.helper.isinfocall(varargin{:}) | |
43 varargout{1} = getInfo(varargin{3}); | |
44 return | |
45 end | |
46 | |
47 import utils.const.* | |
48 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
49 | |
50 % Collect input variable names | |
51 in_names = cell(size(varargin)); | |
52 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
53 | |
54 % Collect all AOs and PLISTs | |
55 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
56 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
57 | |
58 % Define property name | |
59 pName = 'toffset'; | |
60 | |
61 % Get values for the AOs | |
62 [as, values] = processSetterValues(as, pls, rest, pName); | |
63 | |
64 % If no values are specified and there are more than one AOs then take | |
65 % the last AO to be the container (y-values). | |
66 if isempty(values) && numel(as) >= 2 | |
67 values = {as(end).y}; | |
68 as(end) = []; | |
69 end | |
70 | |
71 % Combine input plists and default PLIST | |
72 pls = applyDefaults(getDefaultPlist(), pls); | |
73 | |
74 end % callerIsMethod | |
75 | |
76 % Decide on a deep copy or a modify | |
77 bs = copy(as, nargout); | |
78 | |
79 % Loop over AOs | |
80 for jj = 1:numel(bs) | |
81 if isa(bs(jj).data, 'tsdata') | |
82 bs(jj).data.setToffset(values{jj}*1e3); | |
83 if ~callerIsMethod | |
84 plh = pls.pset(pName, values{jj}); | |
85 bs(jj).addHistory(getInfo('None'), plh, ao_invars(jj), bs(jj).hist); | |
86 end | |
87 else | |
88 error('### Set toffset works only for time series data AOs'); | |
89 end | |
90 end | |
91 | |
92 % Set output | |
93 varargout = utils.helper.setoutputs(nargout, bs); | |
94 end | |
95 | |
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
97 % Local Functions % | |
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
99 %-------------------------------------------------------------------------- | |
100 % Get Info Object | |
101 %-------------------------------------------------------------------------- | |
102 function ii = getInfo(varargin) | |
103 | |
104 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
105 sets = {}; | |
106 pl = []; | |
107 else | |
108 sets = {'Default'}; | |
109 pl = getDefaultPlist(); | |
110 end | |
111 % Build info object | |
112 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: setToffset.m,v 1.3 2011/09/17 03:09:26 hewitson Exp $', sets, pl); | |
113 end | |
114 | |
115 %-------------------------------------------------------------------------- | |
116 % Get Default Plist | |
117 %-------------------------------------------------------------------------- | |
118 function plout = getDefaultPlist() | |
119 persistent pl; | |
120 if ~exist('pl', 'var') || isempty(pl) | |
121 pl = buildplist(); | |
122 end | |
123 plout = pl; | |
124 end | |
125 | |
126 function pl = buildplist() | |
127 pl = plist({'toffset', 'Time offset from t0 to the first data sample in seconds.'}, paramValue.DOUBLE_VALUE(NaN)); | |
128 end |