vectorization_tricks_2

# vectorization_tricks_2 - Drea's Desk Vectorization Tips Ask...

This preview shows pages 1–2. Sign up to view the full content.

Drea's Desk: Vectorization Tips Ask any crusty MATLAB programmer how to speed up your code and they'll tell you "Vectorize!". OK, you say. How? This is a hard question to answer generally because: - There are different techniques for different problems. - There are different techniques for the same problem. - Different techniques are better or worse depending on the matrix size. - There is no end to the clever and obscure ways to vectorize in MATLAB. One nice thing about MATLAB is that you can program in an entirely scalar way and your program will work fine, it just isn't optimal. It is like programming in C without using pointers (directly). You can do it, but you'll probably end up with sub-optimal code. There is an enjoyable puzzle aspect to optimizing M-code. I've known people who spend hours devising intricate indexing tricks to avoid a for loop. The tricks are so complex the result is even slower than having the for loop. Still, you get a certain satisfaction from the exercise. If you want to cause a flurry on comp.soft-sys.matlab, just ask a question like "how do I vectorize this?". There is a group of dedicated "speed freaks" among MATLAB users. All of the winners of the contests in this digest probably qualify. This Desk is primarily targeted toward MATLAB users that have written between 10 and 100 M-files, but I hope more experienced MATLAB programmers will also find a useful tip or two. I've identified three generic programming problems and will describe ways to vectorize them. 1. Find a subset of a matrix that satisfies a condition, and do

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

vectorization_tricks_2 - Drea's Desk Vectorization Tips Ask...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online