Mercurial > hg > ltpda
view m-toolbox/html_help/help/ug/ao_convert_content.html @ 52:daf4eab1a51e database-connection-manager tip
Fix. Default password should be [] not an empty string
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 07 Dec 2011 17:29:47 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
<!-- $Id: ao_convert_content.html,v 1.3 2008/03/03 09:08:10 hewitson Exp $ --> <p> In some cases it is desirable to build AOs 'by hand' from existing data files. If the data file doesn't conform to one of the existing AO constructors, then a conversion script can easily be written to create AOs from your data files. </p> <p>The following example shows how to convert an ASCII data file into Analysis Objects. The data file has 4 columns representing 4 different data channels. All 4 channels are sampled at the same rate of 10Hz. The conversion function returns 4 AOs.</p> <div class="fragment"><pre> <span class="code"> function b = myConverter(filename, fs)</span> <span class="comment">% MYCONVERTER converts a multi-column ASCII data file into multiple AOs.</span> <span class="comment">%</span> <span class="comment">% usage: b = myConverter(filename, fs)</span> <span class="comment">%</span> <span class="comment">% Inputs:</span> <span class="comment">% filename - name of input data file</span> <span class="comment">% fs - sample rate of input data</span> <span class="comment">%</span> <span class="comment">% Outputs:</span> <span class="comment">% b - vector of AOs</span> <span class="comment">%</span> <span class="comment">%</span> <span class="comment">% Load the data from text file</span> data_in = load(filename); ncols = size(data_in, 2); <span class="comment">% Create AOs</span> b = []; <span class="keyword">for</span> j=1:ncols <span class="comment">% Get this column of data</span> d = data_in(:,j); <span class="comment">% name for this data</span> dataName = [<span class="string">'column'</span> num2str(j)]; <span class="comment">% Make tsdata object</span> ts = tsdata(d, fs); <span class="comment">% set name of data object</span> ts = set(ts, <span class="string">'name'</span>, dataName); <span class="comment">% set xunits to seconds</span> ts = set(ts, <span class="string">'xunits'</span>, <span class="string">'s'</span>); <span class="comment">% set xunits to Volts</span> ts = set(ts, <span class="string">'yunits'</span>, <span class="string">'V'</span>); <span class="comment">% make history object</span> h = history(<span class="string">'myConverter'</span>, <span class="string">'0.1'</span>, plist(param(<span class="string">'filename'</span>, filename))); <span class="comment">% make AO</span> a = ao(ts, h); <span class="comment">% set AO name</span> a = set(a, <span class="string">'name'</span>, dataName); <span class="comment">% add to output vector</span> b = [b a]; <span class="keyword">end</span></pre></div> <br> <p> The script works by loading the four columns of data from the ASCII file into a matrix. The script then loops over the number of columns and creates an AO for each column. </p> <p>First a time-series (<tt>tsdata</tt>) object is made from the data in a column and given the input sample rate of the data. The 'name', 'xunits', and 'yunits' fields of the time-series data object are then set using calls to the <tt>set</tt> method of the <tt>tsdata</tt> class. </p> <p> Next a history object is made with its 'name' set to 'myConverter', the version set to '0.1', and the input filename is recorded in a parameter list attached to the history object. </p> <p> Following the creation of the data object and the history object, we can then create an Analysis Object. The name of the AO is then set and the object is added to a vector that is output by the function. </p>