Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/convert.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 % CONVERT perform various conversions on the ao. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: CONVERT perform various conversions on the ao. | |
5 % | |
6 % CALL: ao = convert(ao, pl) | |
7 % | |
8 % PARAMETERS: | |
9 % | |
10 % 'action' - choose a conversion to make [default: none] | |
11 % | |
12 % Possible actions: | |
13 % | |
14 % Unit conversions: | |
15 % 's to Hz' - convert seconds to Hz in the yunits of this AO. | |
16 % 'Hz to s' - convert Hz to seconds in the yunits of this AO. | |
17 % | |
18 % Data conversions: | |
19 % 'to cdata' - convert the data in the AO to a cdata type. | |
20 % 'to tsdata' - convert the data in the AO to a tsdata type. | |
21 % 'to fsdata' - convert the data in the AO to a fsdata type. | |
22 % 'to xydata' - convert the data in the AO to a xydata type. | |
23 % | |
24 % | |
25 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'convert')">Parameters Description</a> | |
26 % | |
27 % VERSION: $Id: convert.m,v 1.13 2011/07/01 14:40:18 ingo Exp $ | |
28 % | |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
30 | |
31 function varargout = convert(varargin) | |
32 | |
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 | |
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 AOs | |
48 [as, ao_invars,rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
49 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
50 | |
51 | |
52 %%% Combine plists | |
53 pl = parse(pls, getDefaultPlist); | |
54 | |
55 % Get action to perform | |
56 action = lower(find(pl, 'action')); | |
57 | |
58 if isempty(action) | |
59 % check rest | |
60 for kk=1:numel(rest) | |
61 if ischar(rest{kk}) | |
62 action = lower(rest{kk}); | |
63 pl.pset('action', action); | |
64 end | |
65 end | |
66 end | |
67 | |
68 % Decide on a deep copy or a modify | |
69 bs = copy(as, nargout); | |
70 | |
71 % Loop over AOs | |
72 for j=1:numel(bs) | |
73 | |
74 switch lower(action) | |
75 case '' | |
76 % do nothing | |
77 case 's to hz' | |
78 secondsToHz(bs(j)); | |
79 case 'hz to s' | |
80 HzToSeconds(bs(j)); | |
81 case 'to cdata' | |
82 tocdata(bs(j)); | |
83 case 'to tsdata' | |
84 totsdata(bs(j)); | |
85 case 'to fsdata' | |
86 tofsdata(bs(j)); | |
87 case 'to xydata' | |
88 toxydata(bs(j)); | |
89 otherwise | |
90 error('### Unknown action requested.'); | |
91 end | |
92 | |
93 % Set history | |
94 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist); | |
95 | |
96 end | |
97 | |
98 % Set output | |
99 if nargout == numel(bs) | |
100 % List of outputs | |
101 for ii = 1:numel(bs) | |
102 varargout{ii} = bs(ii); | |
103 end | |
104 else | |
105 % Single output | |
106 varargout{1} = bs; | |
107 end | |
108 end | |
109 | |
110 %---------------------------------------------- | |
111 % Convert to xydata | |
112 function toxydata(a) | |
113 if isa(a.data, 'cdata') | |
114 x = 1:numel(a.data.y); | |
115 else | |
116 x = a.x; | |
117 end | |
118 a.data = xydata(x, a.data.y); | |
119 end | |
120 | |
121 %---------------------------------------------- | |
122 % Convert to fsdata | |
123 function tofsdata(a) | |
124 if isa(a.data, 'cdata') | |
125 x = 1:numel(a.data.y); | |
126 else | |
127 x = a.x; | |
128 end | |
129 a.data = fsdata(x, a.data.y); | |
130 end | |
131 %---------------------------------------------- | |
132 % Convert to tsdata | |
133 function totsdata(a) | |
134 if isa(a.data, 'cdata') | |
135 x = 1:numel(a.data.y); | |
136 else | |
137 x = a.x; | |
138 end | |
139 a.data = tsdata(x, a.data.y); | |
140 end | |
141 | |
142 %---------------------------------------------- | |
143 % Convert to cdata | |
144 function tocdata(a) | |
145 a.data = cdata(a.data.y); | |
146 end | |
147 | |
148 %---------------------------------------------- | |
149 % Convert any 's' units to 'Hz' in the yunits | |
150 function secondsToHz(a) | |
151 a.data.yunits.sToHz; | |
152 end | |
153 %---------------------------------------------- | |
154 % Convert any 'Hz' units to 's' in the yunits | |
155 function HzToSeconds(a) | |
156 a.data.yunits.HzToS; | |
157 end | |
158 | |
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
160 % Local Functions % | |
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
162 %-------------------------------------------------------------------------- | |
163 % Get Info Object | |
164 %-------------------------------------------------------------------------- | |
165 function ii = getInfo(varargin) | |
166 | |
167 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
168 sets = {}; | |
169 pl = []; | |
170 else | |
171 sets = {'Default'}; | |
172 pl = getDefaultPlist; | |
173 end | |
174 % Build info object | |
175 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: convert.m,v 1.13 2011/07/01 14:40:18 ingo Exp $', sets, pl); | |
176 end | |
177 | |
178 %-------------------------------------------------------------------------- | |
179 % Get Default Plist | |
180 %-------------------------------------------------------------------------- | |
181 | |
182 function plout = getDefaultPlist() | |
183 persistent pl; | |
184 if exist('pl', 'var')==0 || isempty(pl) | |
185 pl = buildplist(); | |
186 end | |
187 plout = pl; | |
188 end | |
189 | |
190 function pl = buildplist() | |
191 pl = plist({'action', 'Choose the action to perform.'}, ... | |
192 {1, {'', 's to Hz', 'Hz to s', 'to cdata', 'to tsdata', 'to fsdata', 'to xydata'}, paramValue.SINGLE}); | |
193 | |
194 end | |
195 |