Getting Started | ![]() ![]() |
Vectorization
To obtain the most speed out of MATLAB, it's important to vectorize the algorithms in your M-files. Where other programming languages might use for
or DO
loops, MATLAB can use vector or matrix operations. A simple example involves creating a table of logarithms.
x = .01; for k = 1:1001 y(k) = log10(x); x = x + .01; end
A vectorized version of the same code is
x = .01:.01:10; y = log10(x);
For more complicated code, vectorization options are not always so obvious. When speed is important, however, you should always look for ways to vectorize your algorithms.
![]() | The eval Function | Preallocation | ![]() |