MATLAB: Compare loops and matrix computation.

loop; matrix

Hi, all,
I recently found that Matlab executes matrix/vector computation pretty fast than scalar computation with loops. For example, if I used loops to execute algorithm, it is very slow. If I convert it to vector or matrix, it is faster.
I was told about this fact before, is there any explanation on it?
The bad thing is that you cannot always use matrix to replace loops…
Thanks.

Best Answer