comparison m-toolbox/html_help/help/ug/ao_convert_content.html @ 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 <!-- $Id: ao_convert_content.html,v 1.3 2008/03/03 09:08:10 hewitson Exp $ -->
2 <p>
3 In some cases it is desirable to build AOs 'by hand' from existing data files. If the data file
4 doesn't conform to one of the existing AO constructors, then a conversion script can easily be
5 written to create AOs from your data files.
6 </p>
7 <p>The following example shows how to convert an ASCII data file into Analysis Objects. The data file
8 has 4 columns representing 4 different data channels. All 4 channels are sampled at the same rate of
9 10Hz. The conversion function returns 4 AOs.</p>
10
11 <div class="fragment"><pre> <span class="code"> function b = myConverter(filename, fs)</span>
12
13 <span class="comment">% MYCONVERTER converts a multi-column ASCII data file into multiple AOs.</span>
14 <span class="comment">%</span>
15 <span class="comment">% usage: b = myConverter(filename, fs)</span>
16 <span class="comment">%</span>
17 <span class="comment">% Inputs:</span>
18 <span class="comment">% filename - name of input data file</span>
19 <span class="comment">% fs - sample rate of input data</span>
20 <span class="comment">%</span>
21 <span class="comment">% Outputs:</span>
22 <span class="comment">% b - vector of AOs</span>
23 <span class="comment">%</span>
24 <span class="comment">%</span>
25
26 <span class="comment">% Load the data from text file</span>
27 data_in = load(filename);
28 ncols = size(data_in, 2);
29
30 <span class="comment">% Create AOs</span>
31 b = [];
32 <span class="keyword">for</span> j=1:ncols
33
34 <span class="comment">% Get this column of data</span>
35 d = data_in(:,j);
36
37 <span class="comment">% name for this data</span>
38 dataName = [<span class="string">'column'</span> num2str(j)];
39
40 <span class="comment">% Make tsdata object</span>
41 ts = tsdata(d, fs);
42 <span class="comment">% set name of data object</span>
43 ts = set(ts, <span class="string">'name'</span>, dataName);
44 <span class="comment">% set xunits to seconds</span>
45 ts = set(ts, <span class="string">'xunits'</span>, <span class="string">'s'</span>);
46 <span class="comment">% set xunits to Volts</span>
47 ts = set(ts, <span class="string">'yunits'</span>, <span class="string">'V'</span>);
48
49 <span class="comment">% make history object</span>
50 h = history(<span class="string">'myConverter'</span>, <span class="string">'0.1'</span>, plist(param(<span class="string">'filename'</span>, filename)));
51
52 <span class="comment">% make AO</span>
53 a = ao(ts, h);
54
55 <span class="comment">% set AO name</span>
56 a = set(a, <span class="string">'name'</span>, dataName);
57
58 <span class="comment">% add to output vector</span>
59 b = [b a];
60
61 <span class="keyword">end</span></pre></div>
62
63 <br>
64 <p>
65 The script works by loading the four columns of data from the ASCII file into a matrix. The
66 script then loops over the number of columns and creates an AO for each column.
67 </p>
68 <p>First a time-series (<tt>tsdata</tt>) object is made from the data in a column and given the
69 input sample rate of the data. The 'name', 'xunits', and 'yunits' fields of the time-series data
70 object are then set using calls to the <tt>set</tt> method of the <tt>tsdata</tt> class.
71 </p>
72 <p>
73 Next a history object is made with its 'name' set to 'myConverter', the version set to '0.1',
74 and the input filename is recorded in a parameter list attached to the history object.
75 </p>
76 <p>
77 Following the creation of the data object and the history object, we can then create an
78 Analysis Object. The name of the AO is then set and the object is added to a vector that is
79 output by the function.
80 </p>