MATLAB utility functions written by Kendrick Kay