1D, 2D, or 3D gamma computation in MATLAB