samer@57
|
1 function [NN,map1]=hist1d(X,m1spec,varargin)
|
samer@57
|
2 % hist1d - 1D histogram
|
samer@57
|
3 %
|
samer@57
|
4 % hist1d ::
|
samer@57
|
5 % [[N,1]] ~'N rows of 1D data',
|
samer@57
|
6 % (K1:natural | dmap(K1)) ~'num bins for dim 1, or bins'
|
samer@57
|
7 % -> [[K1]->natural] ~'bin counts',
|
samer@57
|
8 % dmap(K1) ~'the map'.
|
samer@57
|
9
|
samer@57
|
10 mins=min(X); maxs=max(X)+eps;
|
samer@57
|
11 map1=mkdmap(mins(1),maxs(1),m1spec);
|
samer@57
|
12
|
samer@57
|
13 N=accumhist([map1(X(:,1))],1,[cardr(map1)]);
|
samer@57
|
14 if nargout==0,
|
samer@57
|
15 opts=prefs('log',1,'plot','stairs','plotopts',{},varargin{:});
|
samer@57
|
16 switch opts.plot
|
samer@57
|
17 case 'stairs', plothist_stairs(map1,N,opts.plotopts{:});
|
samer@57
|
18 case 'bars', plothist_bars(map1,N,opts.plotopts{:});
|
samer@57
|
19 case 'line', plot(centres(map1),N,opts.plotopts{:});
|
samer@57
|
20 end
|
samer@57
|
21 if opts.log, semilgy; end
|
samer@57
|
22 xlim(domain(map1));
|
samer@57
|
23 else
|
samer@57
|
24 NN=N;
|
samer@57
|
25 end
|
samer@57
|
26
|
samer@57
|
27
|
samer@57
|
28 function M=mkdmap(min,max,spec)
|
samer@57
|
29
|
samer@57
|
30 if length(spec)==0, spec=32; end
|
samer@57
|
31 if isa(spec,'dmap') % is alread a dmap
|
samer@57
|
32 M=spec;
|
samer@57
|
33 elseif length(spec)==1, % spec=number of bins
|
samer@57
|
34 M=linmap(min,max,spec);
|
samer@57
|
35 else
|
samer@57
|
36 error('invalid discretisation map');
|
samer@57
|
37 end
|
samer@57
|
38
|