view general/discretise/intmap.m @ 4:e44f49929e56

Adding reorganised general toolbox, now in several subdirectories.
author samer
date Sat, 12 Jan 2013 19:21:22 +0000
parents
children
line wrap: on
line source
function M=intmap(min,max)
% intmap - Discretisation map for integers (ie alread discrete)
%
% intmap :: integer~'min value', integer~'max value' -> dmap(N).
%
% Maps integers to natural numbers, saves on multiplications and
% roundings as performed by the real->natural maps.

	N=max-min+1;
	off=min-1;
	M=dmap(N,@map,@revmap);

	function I=map(X)
		I=X-off;
		I(I<1)=-inf;
		I(I>N)=inf;
	end

	function X=revmap(I)
		I=shiftdim(shiftdim(I),-1);
		X1=off+I-0.5;
		X2=off+I+0.5;
		X=cat(1,X1,X2);
	end
end