comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirhisto/mirhisto.m @ 0:e9a9cd732c1e tip

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