view histogram/hist1d.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents ce9021da6ce2
children
line wrap: on
line source
function [NN,map1]=hist1d(X,m1spec,varargin)
% hist1d - 1D histogram
%
% hist1d :: 
%    [[N,1]]	~'N rows of 1D data',
%    (K1:natural | dmap(K1)) ~'num bins for dim 1, or bins'
% -> [[K1]->natural] ~'bin counts',
%    dmap(K1)        ~'the map'.

mins=min(X); maxs=max(X)+eps;
map1=mkdmap(mins(1),maxs(1),m1spec);

N=accumhist([map1(X(:,1))],1,[cardr(map1)]);
if nargout==0,
	opts=prefs('log',1,'plot','stairs','plotopts',{},varargin{:}); 
	switch opts.plot
		case 'stairs', plothist_stairs(map1,N,opts.plotopts{:});
		case 'bars',   plothist_bars(map1,N,opts.plotopts{:});
		case 'line',   plot(centres(map1),N,opts.plotopts{:});
	end
	if opts.log, semilgy; end
	xlim(domain(map1));
else
	NN=N;
end


function M=mkdmap(min,max,spec)

	if length(spec)==0, spec=32; end
	if isa(spec,'dmap') % is alread a dmap
		M=spec;
	elseif length(spec)==1, % spec=number of bins
		M=linmap(min,max,spec);
	else
		error('invalid discretisation map');
	end