Helper functions for MATLAB