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.

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

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

              The following call returns a parameter list object that
              contains the default parameter values:

              >> pl = split(ao, 'Params')

 VERSION:     $Id: split.m,v 1.10 2007/06/22 08:32:49 ingo 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 %              The following call returns a parameter list object that
0031 %              contains the default parameter values:
0032 %
0033 %              >> pl = split(ao, 'Params')
0034 %
0035 % VERSION:     $Id: split.m,v 1.10 2007/06/22 08:32:49 ingo Exp $
0036 %
0037 % HISTORY: 02-03-07 M Hewitson
0038 %            Creation.
0039 %
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 % Check if this is a call for parameters
0043 if nargin == 2
0044   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0045     in = char(varargin{2});
0046     if strcmp(in, 'Params')
0047       bo = getDefaultPL();
0048       return
0049     end
0050   end
0051 end
0052 
0053 % capture input variable names
0054 invars = {};
0055 for j=1:nargin
0056   if isa(varargin{j}, 'ao')
0057     invars = [invars cellstr(inputname(j))];
0058   end
0059 end
0060 
0061 ALGONAME = 'split';
0062 VERSION  = '$Id: split.m,v 1.10 2007/06/22 08:32:49 ingo Exp $';
0063 
0064 % Look at inputs
0065 if nargin < 1
0066   error('### Incorrect number of inputs.')
0067 end
0068 if nargin == 1
0069   as = varargin{1};
0070   pl = plist();
0071 end
0072 if nargin == 2
0073   as = varargin{1};
0074   pl = varargin{2};
0075 end
0076 
0077 % Initialise output
0078 bo = [];
0079 % Unpack parameter list
0080 N           = find(pl, 'N');
0081 times       = find(pl, 'times');
0082 frequencies = find(pl, 'frequencies');
0083 samples     = find(pl, 'samples');
0084 
0085 % look at input data
0086 d = as.data;
0087 % name for this object
0088 if isempty(invars{1})
0089   n1 = as.name;
0090 else
0091   n1 = invars{1};
0092 end
0093 
0094 [x,y] = get_xy_axis(as.data);
0095 
0096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0097 %                       splitting by time or frequency                        %
0098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0099 if ~isempty(times) || ~isempty(frequencies)
0100 
0101   if ~isempty(times)
0102     disp('* splitting by time...');
0103     split_x_axis.type  = 'times';
0104     split_x_axis.value =  times;
0105   else
0106     disp('* splitting by frequency...');
0107     split_x_axis.type  = 'frequencies';
0108     split_x_axis.value =  frequencies;
0109   end
0110 
0111   % examine time list
0112   ntimes = length(split_x_axis.value);
0113   if mod(ntimes, 2) ~= 0
0114     error('### please specify a start and stop for each interval.')
0115   end
0116 
0117   % go over each interval now
0118   for i=1:2:ntimes
0119 
0120     is = split_x_axis.value(i);
0121     ie = split_x_axis.value(i+1);
0122 
0123     idx = find(x>=is & x <ie);
0124 
0125     % Make output analysis object
0126     nameStr = sprintf('split(%s)', d.name);
0127 
0128     % create new output data
0129     d = set_xy_axis(d, x(idx), y(idx));
0130     d = set(d, 'name', nameStr);
0131 
0132     % create new output history
0133     h = history(ALGONAME, VERSION, plist(param(split_x_axis.type, [is ie])), as.hist);
0134     h = set(h, 'invars', invars);
0135 
0136     % make output analysis object
0137     b = ao(d, h);
0138 
0139     % set name
0140     b = set(b, 'name', sprintf('split(%s)', n1));
0141 
0142     % Add to output array
0143     bo = [bo b];
0144 
0145 
0146   end
0147 
0148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0149 %                            splitting by samples                             %
0150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0151 elseif ~isempty(samples)
0152 
0153   disp('* splitting by samples...');
0154 
0155   % examine time list
0156   npairs = length(samples);
0157   if mod(npairs, 2) ~= 0
0158     error('### please specify a start and stop for each interval.')
0159   end
0160 
0161   % go over each interval now
0162   for i=1:2:npairs
0163 
0164     is = samples(i);
0165     ie = samples(i+1);
0166 
0167     % Make output analysis object
0168     nameStr = sprintf('split(%s)', d.name);
0169 
0170     % create new output data
0171     x1 = x(is:ie);
0172     y1 = y(is:ie);
0173     d = set_xy_axis(d, x1, y1);
0174     d = set(d, 'name', nameStr);
0175 
0176     % create new output history
0177     h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0178     h = set(h, 'invars', invars);
0179 
0180     % make output analysis object
0181     b = ao(d, h);
0182 
0183     % set name
0184     b = set(b, 'name', sprintf('split(%s)', n1));
0185 
0186     % Add to output array
0187     bo = [bo b];
0188 
0189   end
0190 
0191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0192 %                            splitting into chuks                             %
0193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0194 elseif ~isempty(N)
0195   disp(sprintf('* splitting into %d chunks', N));
0196   error('### I have not been written yet. Please code me up.');
0197 
0198 else
0199   error('### do not know how to split.')
0200 end
0201 
0202 % Get default params
0203 function plo = getDefaultPL()
0204 
0205 disp('* creating default plist...');
0206 plo = plist();
0207 plo = append(plo, param('times',       []));
0208 plo = append(plo, param('frequencies', []));
0209 plo = append(plo, param('samples',     []));
0210 plo = append(plo, param('N',           []));
0211 disp('* done.');
0212 
0213 % END

Generated on Mon 02-Jul-2007 12:19:41 by m2html © 2003