Matlab implementation of inverse transform sampling in 1D and 2D