Home > classes > @ao > aosplit.m

aosplit

PURPOSE ^

SPLIT an analysis object into the specified segments.

SYNOPSIS ^

function bo = split(varargin)

DESCRIPTION ^

 SPLIT an analysis object into the specified segments. 
 
 >> b = split(a, pl)
 
 Inputs:
   a  - input analysis object
   pl - input parameter list (see below for parameters)
 
 Outputs:
   b - array of analysis objects
 
 Parameters:
   'times'       - an array of start/stop times to split the input ao by
   'frequencies' - an array of start/stop frequencies to split by
   'samples'     - an array of start/stop samples to split by
   'N'           - split into N contiguous pieces
 
 If more than one splitting method is specified, the priority goes like
 the list above. 
 
 The time vector in the output AO retains the original time values 
 (i.e. it doesn't start from zero).
 
 The splitting is done as  s<=t<e.
 
 Arrays of start/stop values should be like: [s1 e1 s2 e2 ....]
 
 M Hewitson 02-03-07
 
 $Id: aosplit.html,v 1.7 2008/01/22 20:43:15 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bo = split(varargin)
0002 
0003 % SPLIT an analysis object into the specified segments.
0004 %
0005 % >> b = split(a, pl)
0006 %
0007 % Inputs:
0008 %   a  - input analysis object
0009 %   pl - input parameter list (see below for parameters)
0010 %
0011 % Outputs:
0012 %   b - array of analysis objects
0013 %
0014 % Parameters:
0015 %   'times'       - an array of start/stop times to split the input ao by
0016 %   'frequencies' - an array of start/stop frequencies to split by
0017 %   'samples'     - an array of start/stop samples to split by
0018 %   'N'           - split into N contiguous pieces
0019 %
0020 % If more than one splitting method is specified, the priority goes like
0021 % the list above.
0022 %
0023 % The time vector in the output AO retains the original time values
0024 % (i.e. it doesn't start from zero).
0025 %
0026 % The splitting is done as  s<=t<e.
0027 %
0028 % Arrays of start/stop values should be like: [s1 e1 s2 e2 ....]
0029 %
0030 % M Hewitson 02-03-07
0031 %
0032 % $Id: aosplit.html,v 1.7 2008/01/22 20:43:15 hewitson Exp $
0033 %
0034 
0035 
0036 % capture input variable names
0037 invars = {};
0038 for j=1:nargin
0039   if isa(varargin{j}, 'ao')
0040     invars = [invars cellstr(inputname(j))];
0041   end
0042 end
0043 
0044 ALGONAME = mfilename;
0045 VERSION  = '$Id: aosplit.html,v 1.7 2008/01/22 20:43:15 hewitson Exp $';
0046 
0047 % Look at inputs
0048 if nargin < 1
0049   error('### Incorrect number of inputs.')
0050 end
0051 if nargin == 1
0052   as = varargin{1};
0053   pl = plist();
0054 end
0055 if nargin == 2
0056   as = varargin{1};
0057   pl = varargin{2};
0058 end
0059 
0060 % Initialise output
0061 bo = [];
0062 % Unpack parameter list
0063 N           = find(pl, 'N');
0064 times       = find(pl, 'times');
0065 frequencies = find(pl, 'frequencies');
0066 samples     = find(pl, 'samples');
0067 
0068 % look at input data
0069 d = as.data;
0070 dinfo = whos('d');
0071 % name for this object
0072 if isempty(invars{1})
0073   n1 = as.name;
0074 else
0075   n1 = invars{1};
0076 end
0077 
0078 %---- Time series
0079 if isa(d, 'tsdata')
0080   
0081   if ~isempty(times)
0082     disp('* splitting by time...');
0083     
0084     % get data
0085     t = d.t;
0086     x = d.x;
0087 
0088     % examine time list
0089     ntimes = length(times);
0090     if mod(ntimes, 2) ~= 0
0091       error('### please specify a start and stop for each interval.')
0092     end
0093     
0094     % go over each interval now
0095     for i=1:2:ntimes
0096       
0097       is = times(i);
0098       ie = times(i+1);
0099 
0100       idx = find(t>=is & t <ie);
0101       xo  = x(idx);
0102       
0103       % Make output analysis object
0104       nameStr = sprintf('split(%s)', d.name);
0105 
0106       % create new output data
0107       data = tsdata(t(idx), x(idx));
0108       data = set(data, 'name', nameStr);
0109       data = set(data, 'xunits', d.xunits);
0110       data = set(data, 'yunits', d.yunits);
0111       data = set(data, 't0', d.t0);
0112 
0113       % create new output history
0114       h = history(ALGONAME, VERSION, plist(param('times', [is ie])), as.hist);
0115       h = set(h, 'invars', invars);
0116 
0117       % make output analysis object
0118       b = ao(data, h);
0119 
0120       % set name
0121       b = set(b, 'name', sprintf('split(%s)', n1));
0122 
0123       % Add to output array
0124       bo = [bo b];
0125       
0126       
0127     end
0128     
0129   elseif ~isempty(samples)
0130     
0131     disp('* splitting by samples...');
0132     error('### I have not been written yet. Please code me up.'); 
0133     
0134   elseif ~isempty(N)
0135     disp(sprintf('* splitting into %d chunks', N));    
0136     error('### I have not been written yet. Please code me up.');
0137     
0138   else
0139     error('### do not know how to split.')
0140   end
0141     
0142 %------ Frequency Series
0143 elseif isa(d, 'fsdata')
0144   
0145   if ~isempty(frequencies)
0146     disp('* splitting by frequency...');
0147     % get data
0148     f  = d.f;
0149     xx = d.xx;
0150 
0151     % examine time list
0152     nfreqs = length(frequencies);
0153     if mod(nfreqs, 2) ~= 0
0154       error('### please specify a start and stop for each interval.')
0155     end
0156     
0157     % go over each interval now
0158     for i=1:2:nfreqs
0159       
0160       is = frequencies(i);
0161       ie = frequencies(i+1);
0162       idx = find(f>=is & f <ie);
0163       
0164       % Make output analysis object
0165       nameStr = sprintf('split(%s)', d.name);
0166 
0167       % create new output data
0168       d = set(d, 'f', f(idx));
0169       d = set(d, 'xx', xx(idx));      
0170 
0171       % create new output history
0172       h = history(ALGONAME, VERSION, plist(param('frequencies', [is ie])), as.hist);
0173       h = set(h, 'invars', invars);
0174 
0175       % make output analysis object
0176       b = ao(d, h);
0177 
0178       % set name
0179       b = set(b, 'name', sprintf('split(%s)', n1));
0180 
0181       % Add to output array
0182       bo = [bo b];
0183       
0184       
0185     end    
0186   elseif ~isempty(samples)
0187     disp('* splitting by samples...');
0188     error('### I have not been written yet. Please code me up.');
0189     
0190   elseif ~isempty(N)
0191     disp(sprintf('* splitting into %d chunks', N));
0192     error('### I have not been written yet. Please code me up.');
0193     
0194   else
0195     error('### do not know how to split.')
0196   end
0197   
0198 else
0199   error('### unknown data type.');
0200 end
0201 
0202 
0203 
0204 % END
0205 
0206

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003