samer@57: function [NN,map1,map2]=hist2d(X,m1spec,m2spec,varargin) samer@57: % hist2d - 2D histogram samer@57: % samer@57: % hist2d :: samer@57: % [[N,2]] ~'N rows of 2D data', samer@57: % (K1:natural | dmap(K1)) ~'num bins for dim 1, or bins', samer@57: % (K2:natural | dmap(K2)) ~'num bins for dim 1, or bins' samer@57: % -> [[K1,K2]->natural] ~'bin counts', samer@57: % dmap(K1), samer@57: % dmap(K2). samer@57: % samer@57: % if second map spec is empty, it means use the same map samer@57: % for both dimensions. samer@57: samer@57: mins=min(X); mm=max(X); maxs=mm+eps(mm); samer@57: map1=mkdmap(mins(1),maxs(1),m1spec,[]); samer@57: map2=mkdmap(mins(2),maxs(2),m2spec,m1spec); samer@57: samer@57: N=accumhist([map1(X(:,1)) map2(X(:,2))],1,[cardr(map1) cardr(map2)]); samer@57: if nargout==0, samer@57: opts=prefs('cmap',@(t)log(1+t),varargin{:}); samer@57: imagexy(centres(map2),centres(map1),opts.cmap(N)); samer@57: else samer@57: NN=N; samer@57: end samer@57: samer@57: samer@57: function M=mkdmap(min,max,spec,def) samer@57: if isempty(spec), spec=def; 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: