Stuart’s MATLAB Videos

Watch and Learn

Vectorizing code in MATLAB

Posted by Doug Hull,

When you vectorize code, you avoid looping through an array and instead do operations on the matrix level. This avoids for loops in MATLAB. The reason for vectorizing are often stylistic. Vectorizing is preferred because it can make your code shorter, easier to read and maintain. This simple example contrasts for loop and vectorized implementations of the same algorithm.
68 views (last 30 days)  | |

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.