Home > classes > @ao > split.m

split

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: split.html,v 1.1 2007/06/08 14:15:03 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: split.html,v 1.1 2007/06/08 14:15:03 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: split.html,v 1.1 2007/06/08 14:15:03 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 
0102       % Make output analysis object
0103       nameStr = sprintf('split(%s)', d.name);
0104 
0105       % create new output data
0106       d = set(d, 't', t(idx));
0107       d = set(d, 'x', x(idx));
0108       d = set(d, 'name', nameStr);
0109 
0110       % create new output history
0111       h = history(ALGONAME, VERSION, plist(param('times', [is ie])), as.hist);
0112       h = set(h, 'invars', invars);
0113 
0114       % make output analysis object
0115       b = ao(d, h);
0116 
0117       % set name
0118       b = set(b, 'name', sprintf('split(%s)', n1));
0119 
0120       % Add to output array
0121       bo = [bo b];
0122       
0123       
0124     end
0125     
0126   elseif ~isempty(samples)
0127     
0128     disp('* splitting by samples...');
0129     % get data
0130     t = d.t;
0131     x = d.x;
0132 
0133     % examine time list
0134     npairs = length(samples);
0135     if mod(npairs, 2) ~= 0
0136       error('### please specify a start and stop for each interval.')
0137     end
0138     
0139     % go over each interval now
0140     for i=1:2:npairs
0141       
0142       is = samples(i);
0143       ie = samples(i+1);
0144       
0145       % Make output analysis object
0146       nameStr = sprintf('split(%s)', d.name);
0147 
0148       % create new output data
0149       d = set(d, 't', t(is:ie));
0150       d = set(d, 'x', x(is:ie));      
0151       d = set(d, 'name', nameStr);
0152       
0153       % create new output history
0154       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0155       h = set(h, 'invars', invars);
0156 
0157       % make output analysis object
0158       b = ao(d, h);
0159 
0160       % set name
0161       b = set(b, 'name', sprintf('split(%s)', n1));
0162 
0163       % Add to output array
0164       bo = [bo b];
0165       
0166       
0167     end
0168     
0169   elseif ~isempty(N)
0170     disp(sprintf('* splitting into %d chunks', N));    
0171     error('### I have not been written yet. Please code me up.');
0172     
0173   else
0174     error('### do not know how to split.')
0175   end
0176     
0177 %------ Frequency Series
0178 elseif isa(d, 'fsdata')
0179   
0180   if ~isempty(frequencies)
0181     disp('* splitting by frequency...');
0182     % get data
0183     f  = d.f;
0184     xx = d.xx;
0185 
0186     % examine time list
0187     nfreqs = length(frequencies);
0188     if mod(nfreqs, 2) ~= 0
0189       error('### please specify a start and stop for each interval.')
0190     end
0191     
0192     % go over each interval now
0193     for i=1:2:nfreqs
0194       
0195       is = frequencies(i);
0196       ie = frequencies(i+1);
0197       idx = find(f>=is & f <ie);
0198       
0199       % Make output analysis object
0200       nameStr = sprintf('split(%s)', d.name);
0201 
0202       % create new output data
0203       d = set(d, 'f', f(idx));
0204       d = set(d, 'xx', xx(idx));      
0205       d = set(d, 'name', nameStr);
0206 
0207       % create new output history
0208       h = history(ALGONAME, VERSION, plist(param('frequencies', [is ie])), as.hist);
0209       h = set(h, 'invars', invars);
0210 
0211       % make output analysis object
0212       b = ao(d, h);
0213 
0214       % set name
0215       b = set(b, 'name', sprintf('split(%s)', n1));
0216 
0217       % Add to output array
0218       bo = [bo b];
0219       
0220       
0221     end    
0222   elseif ~isempty(samples)
0223     disp('* splitting by samples...');
0224     % get data
0225     f  = d.f;
0226     xx = d.xx;
0227 
0228     % examine time list
0229     npairs = length(samples);
0230     if mod(npairs, 2) ~= 0
0231       error('### please specify a start and stop for each interval.')
0232     end
0233     
0234     % go over each interval now
0235     for i=1:2:npairs
0236       
0237       is = samples(i);
0238       ie = samples(i+1);
0239       
0240       % Make output analysis object
0241       nameStr = sprintf('split(%s)', d.name);
0242 
0243       % create new output data
0244       d = set(d, 'f', f(is:ie));
0245       d = set(d, 'xx', xx(is:ie));      
0246       d = set(d, 'name', nameStr);
0247 
0248       % create new output history
0249       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0250       h = set(h, 'invars', invars);
0251 
0252       % make output analysis object
0253       b = ao(d, h);
0254 
0255       % set name
0256       b = set(b, 'name', sprintf('split(%s)', n1));
0257 
0258       % Add to output array
0259       bo = [bo b];
0260       
0261       
0262     end
0263     
0264   elseif ~isempty(N)
0265     disp(sprintf('* splitting into %d chunks', N));
0266     error('### I have not been written yet. Please code me up.');
0267     
0268   else
0269     error('### do not know how to split.')
0270   end
0271   
0272 else
0273   error('### unknown data type.');
0274 end
0275 
0276 
0277 
0278 % END
0279 
0280

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003