Home > classes > @ao > split_old.m

split_old

PURPOSE ^

SPLIT an analysis object into the specified segments.

SYNOPSIS ^

function bo = split(varargin)

DESCRIPTION ^

 SPLIT an analysis object into the specified segments.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: SPLIT an analysis object into the specified segments.

 CALL:        b = split(a, pl)

 INPUTS:      a  - input analysis object
              pl - input parameter list (see below for parameters)

 OTPUTS:      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 ....]

 VERSION:     $Id: split_old.html,v 1.1 2007/07/10 05:37:08 hewitson Exp $

 HISTORY: 02-03-07 M Hewitson
            Creation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function bo = split(varargin)
0002 % SPLIT an analysis object into the specified segments.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SPLIT an analysis object into the specified segments.
0007 %
0008 % CALL:        b = split(a, pl)
0009 %
0010 % INPUTS:      a  - input analysis object
0011 %              pl - input parameter list (see below for parameters)
0012 %
0013 % OTPUTS:      b  - array of analysis objects
0014 %
0015 % PARAMETERS: '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
0021 %              goes like the list above.
0022 %
0023 %              The time vector in the output AO retains the original
0024 %              time values (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 % VERSION:     $Id: split_old.html,v 1.1 2007/07/10 05:37:08 hewitson Exp $
0031 %
0032 % HISTORY: 02-03-07 M Hewitson
0033 %            Creation.
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 % Check if this is a call for parameters
0038 if nargin == 2
0039   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0040     in = char(varargin{2});
0041     if strcmp(in, 'Params')
0042       bo = getDefaultPL();
0043       return
0044     end
0045   end
0046 end
0047 
0048 % capture input variable names
0049 invars = {};
0050 for j=1:nargin
0051   if isa(varargin{j}, 'ao')
0052     invars = [invars cellstr(inputname(j))];
0053   end
0054 end
0055 
0056 ALGONAME = mfilename;
0057 VERSION  = '$Id';
0058 
0059 % Look at inputs
0060 if nargin < 1
0061   error('### Incorrect number of inputs.')
0062 end
0063 if nargin == 1
0064   as = varargin{1};
0065   pl = plist();
0066 end
0067 if nargin == 2
0068   as = varargin{1};
0069   pl = varargin{2};
0070 end
0071 
0072 % Initialise output
0073 bo = [];
0074 % Unpack parameter list
0075 N           = find(pl, 'N');
0076 times       = find(pl, 'times');
0077 frequencies = find(pl, 'frequencies');
0078 samples     = find(pl, 'samples');
0079 
0080 % look at input data
0081 d = as.data;
0082 dinfo = whos('d');
0083 % name for this object
0084 if isempty(invars{1})
0085   n1 = as.name;
0086 else
0087   n1 = invars{1};
0088 end
0089 
0090 %---- Time series
0091 if isa(d, 'tsdata')
0092 
0093   if ~isempty(times)
0094     disp('* splitting by time...');
0095 
0096     % get data
0097     t = d.t;
0098     x = d.x;
0099 
0100     % examine time list
0101     ntimes = length(times);
0102     if mod(ntimes, 2) ~= 0
0103       error('### please specify a start and stop for each interval.')
0104     end
0105 
0106     % go over each interval now
0107     for i=1:2:ntimes
0108 
0109       is = times(i);
0110       ie = times(i+1);
0111 
0112       idx = find(t>=is & t <ie);
0113 
0114       % Make output analysis object
0115       nameStr = sprintf('split(%s)', d.name);
0116 
0117       % create new output data
0118       d = set(d, 't', t(idx));
0119       d = set(d, 'x', x(idx));
0120       d = set(d, 'name', nameStr);
0121 
0122       % create new output history
0123       h = history(ALGONAME, VERSION, plist(param('times', [is ie])), as.hist);
0124       h = set(h, 'invars', invars);
0125 
0126       % make output analysis object
0127       b = ao(d, h);
0128 
0129       % set name
0130       b = set(b, 'name', sprintf('split(%s)', n1));
0131 
0132       % Add to output array
0133       bo = [bo b];
0134 
0135 
0136     end
0137 
0138   elseif ~isempty(samples)
0139 
0140     disp('* splitting by samples...');
0141     % get data
0142     t = d.t;
0143     x = d.x;
0144 
0145     % examine time list
0146     npairs = length(samples);
0147     if mod(npairs, 2) ~= 0
0148       error('### please specify a start and stop for each interval.')
0149     end
0150 
0151     % go over each interval now
0152     for i=1:2:npairs
0153 
0154       is = samples(i);
0155       ie = samples(i+1);
0156 
0157       % Make output analysis object
0158       nameStr = sprintf('split(%s)', d.name);
0159 
0160       % create new output data
0161       d = set(d, 't', t(is:ie));
0162       d = set(d, 'x', x(is:ie));
0163       d = set(d, 'name', nameStr);
0164 
0165       % create new output history
0166       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0167       h = set(h, 'invars', invars);
0168 
0169       % make output analysis object
0170       b = ao(d, h);
0171 
0172       % set name
0173       b = set(b, 'name', sprintf('split(%s)', n1));
0174 
0175       % Add to output array
0176       bo = [bo b];
0177 
0178 
0179     end
0180 
0181   elseif ~isempty(N)
0182     disp(sprintf('* splitting into %d chunks', N));
0183     error('### I have not been written yet. Please code me up.');
0184 
0185   else
0186     error('### do not know how to split.')
0187   end
0188 
0189 %------ Frequency Series
0190 elseif isa(d, 'fsdata')
0191 
0192   if ~isempty(frequencies)
0193     disp('* splitting by frequency...');
0194     % get data
0195     f  = d.f;
0196     xx = d.xx;
0197 
0198     % examine time list
0199     nfreqs = length(frequencies);
0200     if mod(nfreqs, 2) ~= 0
0201       error('### please specify a start and stop for each interval.')
0202     end
0203 
0204     % go over each interval now
0205     for i=1:2:nfreqs
0206 
0207       is = frequencies(i);
0208       ie = frequencies(i+1);
0209       idx = find(f>=is & f <ie);
0210 
0211       % Make output analysis object
0212       nameStr = sprintf('split(%s)', d.name);
0213 
0214       % create new output data
0215       d = set(d, 'f', f(idx));
0216       d = set(d, 'xx', xx(idx));
0217       d = set(d, 'name', nameStr);
0218 
0219       % create new output history
0220       h = history(ALGONAME, VERSION, plist(param('frequencies', [is ie])), as.hist);
0221       h = set(h, 'invars', invars);
0222 
0223       % make output analysis object
0224       b = ao(d, h);
0225 
0226       % set name
0227       b = set(b, 'name', sprintf('split(%s)', n1));
0228 
0229       % Add to output array
0230       bo = [bo b];
0231 
0232 
0233     end
0234   elseif ~isempty(samples)
0235     disp('* splitting by samples...');
0236     % get data
0237     f  = d.f;
0238     xx = d.xx;
0239 
0240     % examine time list
0241     npairs = length(samples);
0242     if mod(npairs, 2) ~= 0
0243       error('### please specify a start and stop for each interval.')
0244     end
0245 
0246     % go over each interval now
0247     for i=1:2:npairs
0248 
0249       is = samples(i);
0250       ie = samples(i+1);
0251 
0252       % Make output analysis object
0253       nameStr = sprintf('split(%s)', d.name);
0254 
0255       % create new output data
0256       d = set(d, 'f', f(is:ie));
0257       d = set(d, 'xx', xx(is:ie));
0258       d = set(d, 'name', nameStr);
0259 
0260       % create new output history
0261       h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0262       h = set(h, 'invars', invars);
0263 
0264       % make output analysis object
0265       b = ao(d, h);
0266 
0267       % set name
0268       b = set(b, 'name', sprintf('split(%s)', n1));
0269 
0270       % Add to output array
0271       bo = [bo b];
0272 
0273 
0274     end
0275 
0276   elseif ~isempty(N)
0277     disp(sprintf('* splitting into %d chunks', N));
0278     error('### I have not been written yet. Please code me up.');
0279 
0280   else
0281     error('### do not know how to split.')
0282   end
0283 
0284 else
0285   error('### unknown data type.');
0286 end
0287 
0288 % Get default params
0289 function plo = getDefaultPL()
0290 
0291 disp('* creating default plist...');
0292 plo = plist();
0293 plo = append(plo, param('times',       []));
0294 plo = append(plo, param('frequencies', []));
0295 plo = append(plo, param('samples',     []));
0296 plo = append(plo, param('N',           []));
0297 disp('* done.');
0298 
0299 
0300 
0301 % END
0302 
0303

Generated on Wed 04-Jul-2007 19:03:10 by m2html © 2003