samer@57: function [NN,map1]=hist1d(X,m1spec,varargin) samer@57: % hist1d - 1D histogram samer@57: % samer@57: % hist1d :: samer@57: % [[N,1]] ~'N rows of 1D data', samer@57: % (K1:natural | dmap(K1)) ~'num bins for dim 1, or bins' samer@57: % -> [[K1]->natural] ~'bin counts', samer@57: % dmap(K1) ~'the map'. samer@57: samer@57: mins=min(X); maxs=max(X)+eps; samer@57: map1=mkdmap(mins(1),maxs(1),m1spec); samer@57: samer@57: N=accumhist([map1(X(:,1))],1,[cardr(map1)]); samer@57: if nargout==0, samer@57: opts=prefs('log',1,'plot','stairs','plotopts',{},varargin{:}); samer@57: switch opts.plot samer@57: case 'stairs', plothist_stairs(map1,N,opts.plotopts{:}); samer@57: case 'bars', plothist_bars(map1,N,opts.plotopts{:}); samer@57: case 'line', plot(centres(map1),N,opts.plotopts{:}); samer@57: end samer@57: if opts.log, semilgy; end samer@57: xlim(domain(map1)); samer@57: else samer@57: NN=N; samer@57: end samer@57: samer@57: samer@57: function M=mkdmap(min,max,spec) samer@57: samer@57: if length(spec)==0, spec=32; end samer@57: if isa(spec,'dmap') % is alread a dmap samer@57: M=spec; samer@57: elseif length(spec)==1, % spec=number of bins samer@57: M=linmap(min,max,spec); samer@57: else samer@57: error('invalid discretisation map'); samer@57: end samer@57: