Reduced calls to mxGetNumberOfDimensions and mxGetDimensions.