0001 function bo = split(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
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
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
0061 bo = [];
0062
0063 N = find(pl, 'N');
0064 times = find(pl, 'times');
0065 frequencies = find(pl, 'frequencies');
0066 samples = find(pl, 'samples');
0067
0068
0069 d = as.data;
0070 dinfo = whos('d');
0071
0072 if isempty(invars{1})
0073 n1 = as.name;
0074 else
0075 n1 = invars{1};
0076 end
0077
0078
0079 if isa(d, 'tsdata')
0080
0081 if ~isempty(times)
0082 disp('* splitting by time...');
0083
0084
0085 t = d.t;
0086 x = d.x;
0087
0088
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
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
0103 nameStr = sprintf('split(%s)', d.name);
0104
0105
0106 d = set(d, 't', t(idx));
0107 d = set(d, 'x', x(idx));
0108 d = set(d, 'name', nameStr);
0109
0110
0111 h = history(ALGONAME, VERSION, plist(param('times', [is ie])), as.hist);
0112 h = set(h, 'invars', invars);
0113
0114
0115 b = ao(d, h);
0116
0117
0118 b = set(b, 'name', sprintf('split(%s)', n1));
0119
0120
0121 bo = [bo b];
0122
0123
0124 end
0125
0126 elseif ~isempty(samples)
0127
0128 disp('* splitting by samples...');
0129
0130 t = d.t;
0131 x = d.x;
0132
0133
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
0140 for i=1:2:npairs
0141
0142 is = samples(i);
0143 ie = samples(i+1);
0144
0145
0146 nameStr = sprintf('split(%s)', d.name);
0147
0148
0149 d = set(d, 't', t(is:ie));
0150 d = set(d, 'x', x(is:ie));
0151 d = set(d, 'name', nameStr);
0152
0153
0154 h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0155 h = set(h, 'invars', invars);
0156
0157
0158 b = ao(d, h);
0159
0160
0161 b = set(b, 'name', sprintf('split(%s)', n1));
0162
0163
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
0178 elseif isa(d, 'fsdata')
0179
0180 if ~isempty(frequencies)
0181 disp('* splitting by frequency...');
0182
0183 f = d.f;
0184 xx = d.xx;
0185
0186
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
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
0200 nameStr = sprintf('split(%s)', d.name);
0201
0202
0203 d = set(d, 'f', f(idx));
0204 d = set(d, 'xx', xx(idx));
0205 d = set(d, 'name', nameStr);
0206
0207
0208 h = history(ALGONAME, VERSION, plist(param('frequencies', [is ie])), as.hist);
0209 h = set(h, 'invars', invars);
0210
0211
0212 b = ao(d, h);
0213
0214
0215 b = set(b, 'name', sprintf('split(%s)', n1));
0216
0217
0218 bo = [bo b];
0219
0220
0221 end
0222 elseif ~isempty(samples)
0223 disp('* splitting by samples...');
0224
0225 f = d.f;
0226 xx = d.xx;
0227
0228
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
0235 for i=1:2:npairs
0236
0237 is = samples(i);
0238 ie = samples(i+1);
0239
0240
0241 nameStr = sprintf('split(%s)', d.name);
0242
0243
0244 d = set(d, 'f', f(is:ie));
0245 d = set(d, 'xx', xx(is:ie));
0246 d = set(d, 'name', nameStr);
0247
0248
0249 h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0250 h = set(h, 'invars', invars);
0251
0252
0253 b = ao(d, h);
0254
0255
0256 b = set(b, 'name', sprintf('split(%s)', n1));
0257
0258
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
0279
0280