MATLAB: How to have the “Matrix dimensions must agree” error message show the sizes of the matrices involved

MATLAB

When developing code, it would be useful if MATLAB showed the dimensions of the matrices when reporting the following error:
??? Error using ==> times
Matrix dimensions must agree.
In my code, this error occurs occasionally due to special cases in my data. As of now, I echo the sizes of the matrices to the screen, which clutters the MATLAB Command Window.

Best Answer

The ability to display the sizes of the matrices involved when reporting the "Matrix dimensions must agree" error is not available in MATLAB.
To work around this issue, either echo the matrix dimensions to the Command Window or enter the following command before executing your code:
dbstop if error
If an error occurs in your code, the MATLAB Debugger starts and you will have access to the matrices that caused the error.