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
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
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
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
0073 bo = [];
0074
0075 N = find(pl, 'N');
0076 times = find(pl, 'times');
0077 frequencies = find(pl, 'frequencies');
0078 samples = find(pl, 'samples');
0079
0080
0081 d = as.data;
0082 dinfo = whos('d');
0083
0084 if isempty(invars{1})
0085 n1 = as.name;
0086 else
0087 n1 = invars{1};
0088 end
0089
0090
0091 if isa(d, 'tsdata')
0092
0093 if ~isempty(times)
0094 disp('* splitting by time...');
0095
0096
0097 t = d.t;
0098 x = d.x;
0099
0100
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
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
0115 nameStr = sprintf('split(%s)', d.name);
0116
0117
0118 d = set(d, 't', t(idx));
0119 d = set(d, 'x', x(idx));
0120 d = set(d, 'name', nameStr);
0121
0122
0123 h = history(ALGONAME, VERSION, plist(param('times', [is ie])), as.hist);
0124 h = set(h, 'invars', invars);
0125
0126
0127 b = ao(d, h);
0128
0129
0130 b = set(b, 'name', sprintf('split(%s)', n1));
0131
0132
0133 bo = [bo b];
0134
0135
0136 end
0137
0138 elseif ~isempty(samples)
0139
0140 disp('* splitting by samples...');
0141
0142 t = d.t;
0143 x = d.x;
0144
0145
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
0152 for i=1:2:npairs
0153
0154 is = samples(i);
0155 ie = samples(i+1);
0156
0157
0158 nameStr = sprintf('split(%s)', d.name);
0159
0160
0161 d = set(d, 't', t(is:ie));
0162 d = set(d, 'x', x(is:ie));
0163 d = set(d, 'name', nameStr);
0164
0165
0166 h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0167 h = set(h, 'invars', invars);
0168
0169
0170 b = ao(d, h);
0171
0172
0173 b = set(b, 'name', sprintf('split(%s)', n1));
0174
0175
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
0190 elseif isa(d, 'fsdata')
0191
0192 if ~isempty(frequencies)
0193 disp('* splitting by frequency...');
0194
0195 f = d.f;
0196 xx = d.xx;
0197
0198
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
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
0212 nameStr = sprintf('split(%s)', d.name);
0213
0214
0215 d = set(d, 'f', f(idx));
0216 d = set(d, 'xx', xx(idx));
0217 d = set(d, 'name', nameStr);
0218
0219
0220 h = history(ALGONAME, VERSION, plist(param('frequencies', [is ie])), as.hist);
0221 h = set(h, 'invars', invars);
0222
0223
0224 b = ao(d, h);
0225
0226
0227 b = set(b, 'name', sprintf('split(%s)', n1));
0228
0229
0230 bo = [bo b];
0231
0232
0233 end
0234 elseif ~isempty(samples)
0235 disp('* splitting by samples...');
0236
0237 f = d.f;
0238 xx = d.xx;
0239
0240
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
0247 for i=1:2:npairs
0248
0249 is = samples(i);
0250 ie = samples(i+1);
0251
0252
0253 nameStr = sprintf('split(%s)', d.name);
0254
0255
0256 d = set(d, 'f', f(is:ie));
0257 d = set(d, 'xx', xx(is:ie));
0258 d = set(d, 'name', nameStr);
0259
0260
0261 h = history(ALGONAME, VERSION, plist(param('samples', [is ie])), as.hist);
0262 h = set(h, 'invars', invars);
0263
0264
0265 b = ao(d, h);
0266
0267
0268 b = set(b, 'name', sprintf('split(%s)', n1));
0269
0270
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
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
0302
0303