comparison m-toolbox/classes/@ao/fromXYVals.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 % FROMXYVALS Construct an ao from a value set
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromXYVals
5 %
6 % DESCRIPTION: Construct an ao from a value set
7 %
8 % CALL: a = aoFromXYVals(a, vals)
9 %
10 % PARAMETER: vals: Constant values
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 function a = fromXYVals(a, pli, callerIsMethod)
14
15 VERSION = '$Id: fromXYVals.m,v 1.20 2011/08/15 05:03:31 hewitson Exp $';
16
17 if callerIsMethod
18 % do nothing
19 else
20 % get AO info
21 ii = ao.getInfo('ao', 'From XY Values');
22
23 % Set the method version string in the minfo object
24 ii.setMversion([VERSION '-->' ii.mversion]);
25 end
26
27 if callerIsMethod
28 pl = pli;
29 pl_unused = plist();
30 else
31 % Combine input plist with default values
32 % TODO: the parse step should be removed and included somehow into plist/applyDefaults
33 [pl, pl_unused] = applyDefaults(ii.plists, pli);
34 end
35
36 % Get values from the plist
37 xvals = find(pl, 'xvals');
38 yvals = find(pl, 'yvals');
39 fs = find(pl, 'fs');
40 dtype = find(pl, 'type');
41 t0 = find(pl, 't0');
42
43 % Create an AO with cdata if no value is set
44 if isempty(xvals) && isempty(yvals)
45 error('### Please specify some X and Y values.');
46 end
47
48 % Try to decide what to do if the user doesn't specify dtype
49 if isempty(dtype)
50 if ~isempty(yvals)
51 if ~isempty(fs)
52 dtype = 'tsdata';
53 else
54 dtype = 'xydata';
55 end
56 else
57 dtype = 'cdata';
58 end
59 end
60
61 %--------- Now decide what to construct
62 switch lower(dtype)
63
64 case 'tsdata'
65 if ~isempty(xvals) && ~isempty(yvals) && ~isempty(fs)
66 data_obj = tsdata(xvals, yvals, fs);
67 elseif ~isempty(xvals) && ~isempty(yvals)
68 data_obj = tsdata(xvals, yvals);
69 elseif ~isempty(yvals) && ~isempty(fs)
70 data_obj = tsdata(yvals, fs);
71 else
72 error('### To build an AO with tsdata please specify at least yvals and fs');
73 end
74 if ~isempty(t0)
75 data_obj.setT0(time(t0));
76 else
77 data_obj.setT0(time(0));
78 end
79
80 % Handle toffset
81 % For evenly sampled which means the original toffset of the data has
82 % been put in the toffset field, so we need to add the user
83 % specified toffset.
84 % For unevenly sampled data, the data object is constructed with a
85 % toffset of zero. In any case the following works for both cases
86 % except when this is called from a method, in which case we don't
87 % apply the defaults and the toffset could be []. MATLAB returns []
88 % when you do <double> + [], so we need to check that the plist value
89 % of toffset is not empty before doing the sum.
90 if ~isempty(pl.find('toffset'))
91 toffset = data_obj.toffset + 1000*pl.find('toffset');
92 data_obj.setToffset(toffset);
93 end
94
95 case 'fsdata'
96 if ~isempty(xvals) && ~isempty(yvals) && ~isempty(fs)
97 data_obj = fsdata(xvals, yvals, fs);
98 elseif ~isempty(xvals) && ~isempty(yvals)
99 data_obj = fsdata(xvals, yvals);
100 elseif ~isempty(yvals) && ~isempty(fs)
101 data_obj = fsdata(yvals, fs);
102 else
103 error('### To build an AO with fsdata please specify at least xvals and yvals');
104 end
105
106 case 'xydata'
107 if ~isempty(xvals) && ~isempty(yvals)
108 data_obj = xydata(xvals, yvals);
109 elseif ~isempty(yvals)
110 data_obj = xydata(yvals);
111 else
112 error('### To build an AO with xydata please specify at least yvals');
113 end
114
115 case 'cdata'
116 if ~isempty(yvals)
117 data_obj = cdata(yvals);
118 else
119 error('### To build an AO with cdata please specify yvals');
120 end
121
122 otherwise
123 error('### Can not build a data object with the given parameters.');
124
125 end
126
127 if isa(data_obj, 'fsdata')
128 if eq(unit(pl.find('xunits')), unit(''))
129 pl.pset('xunits', 'Hz');
130 end
131 elseif isa(data_obj, 'tsdata')
132 if eq(unit(pl.find('xunits')), unit(''))
133 pl.pset('xunits', 's');
134 end
135 end
136
137 % Set data
138 a.data = data_obj;
139
140 a.setXunits(find(pl, 'xunits'));
141 a.setYunits(find(pl, 'yunits'));
142
143 if callerIsMethod
144 % do nothing
145 else
146 % Add history
147 a.addHistory(ii, pl, [], []);
148 end
149
150 % Set the object properties from the plist
151 a.setObjectProperties(pl);
152
153 end
154