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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2011 for the course MATH 571 taught by Professor Staff during the Winter '08 term at University of Michigan.

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 Right Arrow Icon
Ask a homework question - tutors are online