annotate sequences/+seq/merger.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
9e7be347b3a0 |
children |
|
rev |
line source |
samer@36
|
1 % merger - Combine several seq sources using a given function
|
samer@3
|
2 %
|
samer@36
|
3 % merger ::
|
samer@3
|
4 % ( (A1,...,An)->natural ~ chooser function,
|
samer@3
|
5 % n:natural ~ number of sources to combine,
|
samer@3
|
6 % seq A1,...,seq An ~ n seq sources,
|
samer@3
|
7 % ... ~ options
|
samer@3
|
8 % ) -> seq B
|
samer@36
|
9 classdef merger < seq
|
samer@3
|
10 properties (GetAccess=private, SetAccess=private)
|
samer@3
|
11 fn
|
samer@3
|
12 sources
|
samer@3
|
13 hd
|
samer@3
|
14 end
|
samer@3
|
15 methods
|
samer@36
|
16 function d=merger(c,sources,varargin)
|
samer@3
|
17 d.fn=c;
|
samer@3
|
18 d.hd=[];
|
samer@3
|
19 d.sources=sources;
|
samer@3
|
20 end
|
samer@3
|
21
|
samer@3
|
22
|
samer@3
|
23 function x=head(d), x=d.hd; end
|
samer@3
|
24 function d=next(d)
|
samer@3
|
25 data=cellmap(@head,d.sources);
|
samer@23
|
26 if isempty(data), d=nil
|
samer@3
|
27 else
|
samer@3
|
28 k=d.fn(data);
|
samer@3
|
29 d.hd=data{k};
|
samer@3
|
30 nk=next(d.sources{k});
|
samer@3
|
31 if isempty(nk), d.sources(k)=[];
|
samer@3
|
32 else d.sources{k}=nk; end
|
samer@3
|
33 end
|
samer@3
|
34 end
|
samer@3
|
35
|
samer@3
|
36 function z=elsize(d), z=size(d.hd); end
|
samer@3
|
37 function s=tostring(d)
|
samer@8
|
38 s=sprintf('{ %s } >> merge(%s)',catsep(',',cellmap(@tostring,d.sources)),tostring(d.fn));
|
samer@3
|
39 end
|
samer@3
|
40 end
|
samer@3
|
41 end
|