comparison m-toolbox/classes/@ao/fromDataInMAT.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 % FROMDATAINMAT Convert a saved data-array into an AO with a tsdata-object
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % FUNCTION: fromDataInMAT
5 %
6 % DESCRIPTION: Convert a saved data-array into an AO with a tsdata-object
7 %
8 % CALL: obj = fromLISO(obj, data-array, plist)
9 %
10 % PARAMETER: data-array: data-array
11 % plist: plist-object (must contain the filename)
12 %
13 % VERSION: $Id: fromDataInMAT.m,v 1.8 2011/08/12 11:38:03 hewitson Exp $
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 function objs = fromDataInMAT(obj, loadData, pli)
18
19 VERSION = '$Id: fromDataInMAT.m,v 1.8 2011/08/12 11:38:03 hewitson Exp $';
20
21 ii = obj.getInfo(class(obj), 'From MAT Data File');
22
23 % Set the method version string in the minfo object
24 ii.setMversion([VERSION '-->' ii.mversion]);
25
26 %%%%%%%%%% Get default parameter list %%%%%%%%%%
27 dpl = ii.plists();
28 pl = applyDefaults(dpl, pli);
29
30 % Get filename
31 filename = find(pli, 'filename');
32 [pathstr, f_name, ext] = fileparts(filename);
33
34 pl = pset(pl, 'filename', [f_name ext]);
35 pl = pset(pl, 'filepath', pathstr);
36
37 data_type = find (pl, 'type');
38 columns = find (pl, 'columns');
39 fs = find (pl, 'fs');
40
41 objs = [];
42
43 %%%%
44 if strcmpi(data_type, 'cdata')
45 fs = 1;
46 end
47
48 % Then we try for a numerical data set in
49 % the first numerical field we come to
50 fnames = fieldnames(loadData);
51 for jj=1:length(fnames)
52 if isnumeric(loadData.(fnames{jj}))
53 % get the data from here
54 data = loadData.(fnames{jj});
55
56 if isempty(columns)
57 columns = 1:size(data,2);
58 end
59
60 if max(columns) > size(data,2)
61 error('### The stored variable [%s] doesn''t contain %d columns. It only contains %d columns.', fnames{jj}, max(columns), size(data,2));
62 end
63
64 if isempty(fs)
65
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%% Create from x and y %%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70 for kk=1:2:numel(columns)
71
72 % Create an empty object.
73 obj = obj.initObjectWithSize(1,1);
74
75 x = data(:, columns(kk));
76 y = data(:, columns(kk+1));
77
78 switch lower(data_type)
79 case 'tsdata'
80 dataObj = tsdata(x, y);
81 case 'fsdata'
82 dataObj = fsdata(x, y);
83 case 'xydata'
84 dataObj = xydata(x, y);
85 case 'cdata'
86 error('### Should not happen');
87 otherwise
88 error('### unknown data type ''%s''', data_type);
89 end
90
91 obj.data = dataObj;
92
93 plh = pl.pset('columns', [columns(kk) columns(kk+1)]);
94 if isempty(pl.find('Name'))
95 plh.pset('Name', sprintf('%s_%d_%d', find(pl, 'filename'), columns(kk), columns(kk+1)));
96 end
97
98 obj.addHistory(ii, plh, [], []);
99
100 objs = [objs obj];
101
102 end
103
104 else
105
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %%% Create from y and fs %%%
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
110 for kk=1:numel(columns)
111
112 % Create an empty object.
113 obj = obj.initObjectWithSize(1,1);
114
115 y = data(:, columns(kk));
116
117 switch lower(data_type)
118 case 'tsdata'
119 dataObj = tsdata(y, fs);
120 case 'fsdata'
121 dataObj = fsdata(y, fs);
122 case 'xydata'
123 dataObj = xydata(y);
124 case 'cdata'
125 % Special case for cdata objects.
126 % If the user doesn't specify any columns then return only
127 % one AO with all the data. But if the user defines any
128 % columns then return for each column an AO
129 pl.removeKeys({'fs', 'xunits'});
130 if isempty(pl.find('columns'))
131 obj = obj.initObjectWithSize(1,1);
132 obj.data = cdata(data);
133 obj.name = pl.find('filename');
134 obj.addHistory(ii, pl, [], []);
135 objs = [objs obj];
136 break;
137 else
138 dataObj = cdata(data(:,columns));
139 end
140 otherwise
141 error('### unknown data type ''%s''', data_type);
142 end
143
144 obj.data = dataObj;
145
146 plh = pl.pset('columns', columns(kk));
147 if isempty(pl.find('Name'))
148 plh.pset('Name', sprintf('%s_%d', find(pl, 'filename'), columns(kk)));
149 end
150
151 % add history
152 obj.addHistory(ii, plh, [], []);
153
154 objs = [objs obj];
155 end
156
157 end
158
159 % set any object properties
160 objs.setObjectProperties(pl);
161
162 end % End if the mat file contains numeric data
163 end % End loop over filenames
164
165
166 end
167
168
169