comparison sequences/@bufferdata/bufferdata.m @ 0:672052bd81f8

Initial partial import.
author samer
date Wed, 19 Dec 2012 22:38:28 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:672052bd81f8
1 function a=bufferdata(source,L,varargin)
2 % bufferdata - collect elements of sequence into sequence of arrays
3 %
4 % bufferdata ::
5 % data [[N]] ~'source signal',
6 % L:natural ~'buffer width',
7 % -> data [[N,L]]. ~'buffered sequence (no-overlapping)'.
8
9
10 if nargin==1 && isa(source,'bufferdata'), a=source;
11 elseif nargin==0, a=bufferdata([],1);
12 else
13 sz=size1(source);
14
15 a.dim = length(sz)+1;
16 a.width = L;
17 [a.buf,source] = readcat(a.dim,source,L);
18
19 if isempty(a.buf), a=[];
20 else
21 % sort out function table
22 ft.datafn=@datafn;
23 ft.stringfn=@stringfn;
24 ft.nextfn = @nextfn;
25
26 a=class(a,'bufferdata',ddata(source,[sz L],ft));
27 end
28 end
29
30 function s=stringfn(a), s=sprintf('buffer(%d)',a.width);
31 function x=datafn(a), x=a.buf;
32 function a=nextfn(a)
33 % read next lot of values and make an array
34 src=source(a);
35 [a.buf,src]=readcat(a.dim,source(a),a.width);
36 if isempty(a.buf), a=[];
37 else
38 a=setsource(a,src);
39 %!! what if i<L?
40 %a.length=size(source(a),a.dim);
41 end
42
43 function [buf,src]=readcat(dim,src,L)
44 buf=[];
45 for i=1:L
46 if isempty(src), break; end
47 buf=cat(dim,buf,head(src));
48 src=next(src);
49 end
50