Useful MATLAB and MEX functions