wolffd@0
|
1 function varargout = mirhisto(x,varargin)
|
wolffd@0
|
2 % h = mirhisto(x) constructs the histogram from x. The elements of x are
|
wolffd@0
|
3 % binned into equally spaced containers.
|
wolffd@0
|
4 % Optional argument:
|
wolffd@0
|
5 % mirhisto(...,'Number',n): specifies the number of containers.
|
wolffd@0
|
6 % Default value : n = 10.
|
wolffd@0
|
7 % mirhisto(...,'Ampli'): adds the amplitude of the elements,instead of
|
wolffd@0
|
8 % simply counting then.
|
wolffd@0
|
9
|
wolffd@0
|
10
|
wolffd@0
|
11 n.key = 'Number';
|
wolffd@0
|
12 n.type = 'Integer';
|
wolffd@0
|
13 n.default = 10;
|
wolffd@0
|
14 option.n = n;
|
wolffd@0
|
15
|
wolffd@0
|
16 a.key = 'Ampli';
|
wolffd@0
|
17 a.type = 'Boolean';
|
wolffd@0
|
18 a.default = 0;
|
wolffd@0
|
19 option.a = a;
|
wolffd@0
|
20
|
wolffd@0
|
21 specif.option = option;
|
wolffd@0
|
22
|
wolffd@0
|
23
|
wolffd@0
|
24 varargout = mirfunction(@mirhisto,x,varargin,nargout,specif,@init,@main);
|
wolffd@0
|
25
|
wolffd@0
|
26
|
wolffd@0
|
27 function [x type] = init(x,option)
|
wolffd@0
|
28 type = 'mirhisto';
|
wolffd@0
|
29
|
wolffd@0
|
30
|
wolffd@0
|
31 function h = main(x,option,postoption)
|
wolffd@0
|
32 if iscell(x)
|
wolffd@0
|
33 x = x{1};
|
wolffd@0
|
34 end
|
wolffd@0
|
35 d = get(x,'Data');
|
wolffd@0
|
36 %disp('Computing histogram...')
|
wolffd@0
|
37 ddd = cell(1,length(d));
|
wolffd@0
|
38 bbb = cell(1,length(d));
|
wolffd@0
|
39 for i = 1:length(d)
|
wolffd@0
|
40 di = d{i}{1}; % To be generalized for segmented data
|
wolffd@0
|
41 if iscell(di)
|
wolffd@0
|
42 mx = -Inf;
|
wolffd@0
|
43 mn = Inf;
|
wolffd@0
|
44 nc = size(di,2);
|
wolffd@0
|
45 for k = 1:nc
|
wolffd@0
|
46 dk = di{k};
|
wolffd@0
|
47 if size(dk,4) == 2
|
wolffd@0
|
48 dk(end+1:end*2,:,:,1) = dk(:,:,:,2);
|
wolffd@0
|
49 dk(:,:,:,2) = [];
|
wolffd@0
|
50 end
|
wolffd@0
|
51 mxk = max(dk);
|
wolffd@0
|
52 mnk = min(dk);
|
wolffd@0
|
53 if mxk > mx
|
wolffd@0
|
54 mx = mxk;
|
wolffd@0
|
55 end
|
wolffd@0
|
56 if mnk < mn
|
wolffd@0
|
57 mn = mnk;
|
wolffd@0
|
58 end
|
wolffd@0
|
59 end
|
wolffd@0
|
60 if isinf(mx) || isinf(mx)
|
wolffd@0
|
61 b = [];
|
wolffd@0
|
62 dd = [];
|
wolffd@0
|
63 else
|
wolffd@0
|
64 dd = zeros(1,option.n);
|
wolffd@0
|
65 if mn == mx
|
wolffd@0
|
66 b(1,:) = mn-ceil(option.n/2) : mn+floor(option.n/2);
|
wolffd@0
|
67 else
|
wolffd@0
|
68 b(1,:) = mn : (mx-mn)/option.n : mx;
|
wolffd@0
|
69 end
|
wolffd@0
|
70 for k = 1:nc
|
wolffd@0
|
71 dk = di{k};
|
wolffd@0
|
72 for j = 1:option.n
|
wolffd@0
|
73 found = find(and(dk>=b(1,j),dk<=b(1,j+1)));
|
wolffd@0
|
74 if option.a
|
wolffd@0
|
75 dd(1,j) = dd(1,j) + sum(dk(found));
|
wolffd@0
|
76 else
|
wolffd@0
|
77 dd(1,j) = dd(1,j) + length(found);
|
wolffd@0
|
78 end
|
wolffd@0
|
79 end
|
wolffd@0
|
80 end
|
wolffd@0
|
81 end
|
wolffd@0
|
82 else
|
wolffd@0
|
83 if isa(x,'mirscalar')
|
wolffd@0
|
84 di = permute(di,[3 2 1]);
|
wolffd@0
|
85 end
|
wolffd@0
|
86 if size(di,4) == 2
|
wolffd@0
|
87 di(end+1:end*2,:,:,1) = di(:,:,:,2);
|
wolffd@0
|
88 di(:,:,:,2) = [];
|
wolffd@0
|
89 end
|
wolffd@0
|
90 nl = size(di,1);
|
wolffd@0
|
91 nc = size(di,2);
|
wolffd@0
|
92 np = size(di,3);
|
wolffd@0
|
93 dd = zeros(1,option.n,np);
|
wolffd@0
|
94 for l = 1:np
|
wolffd@0
|
95 mx = max(max(di(:,:,l),[],1),[],2);
|
wolffd@0
|
96 mn = min(min(di(:,:,l),[],1),[],2);
|
wolffd@0
|
97 b(l,:) = mn:(mx-mn)/option.n:mx;
|
wolffd@0
|
98 for k = 1:nc
|
wolffd@0
|
99 dk = di(:,k,l);
|
wolffd@0
|
100 for j = 1:option.n
|
wolffd@0
|
101 found = (find(and(dk>=b(l,j),dk<=b(l,j+1))));
|
wolffd@0
|
102 if option.a
|
wolffd@0
|
103 dd(1,j,l) = dd(1,j,l) + sum(dk(found));
|
wolffd@0
|
104 else
|
wolffd@0
|
105 dd(1,j,l) = dd(1,j,l) + length(found);
|
wolffd@0
|
106 end
|
wolffd@0
|
107 end
|
wolffd@0
|
108 end
|
wolffd@0
|
109 end
|
wolffd@0
|
110 end
|
wolffd@0
|
111 ddd{i} = ipermute(dd,[3 2 1]);
|
wolffd@0
|
112 bbb{i}(:,:,1) = b(:,1:end-1);
|
wolffd@0
|
113 bbb{i}(:,:,2) = b(:,2:end);
|
wolffd@0
|
114 end
|
wolffd@0
|
115 h = class(struct,'mirhisto',mirdata(x));
|
wolffd@0
|
116 h = purgedata(h);
|
wolffd@0
|
117 h = set(h,'Bins',bbb,'Weight',ddd); |