Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/offset.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 % OFFSET adds an offset to the data in the AO. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: OFFSET adds an offset to the data in the AO. | |
5 % | |
6 % CALL: ao_out = offset(ao_in); | |
7 % ao_out = offset(ao_in, pl); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'offset')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: offset.m,v 1.15 2011/04/08 08:56:15 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = offset(varargin) | |
16 | |
17 import utils.const.* | |
18 | |
19 % Check if this is a call for parameters | |
20 if utils.helper.isinfocall(varargin{:}) | |
21 varargout{1} = getInfo(varargin{3}); | |
22 return | |
23 end | |
24 | |
25 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
26 | |
27 % Collect input variable names | |
28 in_names = cell(size(varargin)); | |
29 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
30 | |
31 % Collect all AOs | |
32 [as, ao_invars,rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
33 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
34 | |
35 % Get default parameters | |
36 pl = parse(pls, getDefaultPlist); | |
37 | |
38 % Get the offset from the plist | |
39 offset = find(pl, 'offset'); | |
40 | |
41 if isa(offset, 'ao') | |
42 for kk = 1:numel(as) | |
43 if eq(offset.yunits, as(kk).yunits) || eq(offset.yunits, unit) | |
44 offsety = offset.y; | |
45 else | |
46 error('### The offset units must be empty or consistent with those of the input objects') | |
47 end | |
48 end | |
49 offset = offsety; | |
50 end | |
51 | |
52 % look in rest | |
53 if isempty(offset) && ~isempty(rest) | |
54 offset = rest{1}; | |
55 end | |
56 | |
57 % now check we got a factor | |
58 if isempty(offset) || ~isnumeric(offset) || numel(offset) ~= 1 | |
59 error('### The offset must be a single numeric value.'); | |
60 end | |
61 | |
62 % Set the offset to the plist. | |
63 % It might be that the offset was not in the plist | |
64 pl.pset('offset', offset); | |
65 | |
66 % Decide on a deep copy or a modify | |
67 bs = copy(as, nargout); | |
68 | |
69 % Apply method to all AOs | |
70 for kk = 1:numel(bs) | |
71 bs(kk).data.setY(bs(kk).data.y + offset); | |
72 % set name | |
73 bs(kk).name = sprintf('(%s+%g)', bs(kk).name, offset); | |
74 % add history | |
75 bs(kk).addHistory(getInfo('None'), pl, ao_invars(kk), as(kk).hist); | |
76 end | |
77 | |
78 % Set output | |
79 if nargout == numel(bs) && numel(bs)>1 | |
80 for ii = 1:numel(bs) | |
81 varargout{ii} = bs(ii); | |
82 end | |
83 else | |
84 varargout{1} = bs; | |
85 end | |
86 end | |
87 | |
88 %-------------------------------------------------------------------------- | |
89 % Get Info Object | |
90 %-------------------------------------------------------------------------- | |
91 function ii = getInfo(varargin) | |
92 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
93 sets = {}; | |
94 pl = []; | |
95 else | |
96 sets = {'Default'}; | |
97 pl = getDefaultPlist; | |
98 end | |
99 % Build info object | |
100 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: offset.m,v 1.15 2011/04/08 08:56:15 hewitson Exp $', sets, pl); | |
101 end | |
102 | |
103 %-------------------------------------------------------------------------- | |
104 % Get Default Plist | |
105 %-------------------------------------------------------------------------- | |
106 function plout = getDefaultPlist() | |
107 persistent pl; | |
108 if exist('pl', 'var')==0 || isempty(pl) | |
109 pl = buildplist(); | |
110 end | |
111 plout = pl; | |
112 end | |
113 | |
114 function pl = buildplist() | |
115 | |
116 pl = plist({'offset', ['The offset to add.<br>' ... | |
117 'It can be a double or an ao. In this latter case, <br>' ... | |
118 'the units should be empty or matching those of the input objects']}, paramValue.EMPTY_DOUBLE); | |
119 | |
120 end | |
121 | |
122 % PARAMETERS: | |
123 % 'offset' - the offset to add [default: empty] | |
124 | |
125 % END |