Writing_Fast_MATLAB_Code

# Writing_Fast_MATLAB_Code - Writing Fast MATLAB Code Pascal...

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

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.

Unformatted text preview: Writing Fast MATLAB Code Pascal Getreuer August 11, 2004 Contents 1 The Pro ler 2 2 Array Preallocation 3 3 Vectorization 5 3.1 Vectorized Computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.2 Vectorized Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.3 Example 1: Removing elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.4 Example 2: Piecewise functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.5 Example 3: Drawing images with meshgrid . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.6 Example 4: Polynomial interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 Referencing Operations 11 4.1 Subscripts vs. Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.2 Vectorized Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.3 Vector Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.4 Reference Wildcards, : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.5 Deleting Submatrices with [ ] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5 Miscellaneous Tricks 13 5.1 Convert any array into a column vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 Get the number of elements in an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.3 Bound a value without if statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.4 Find the min/max of a matrix or N-d array . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.5 Repeating/tiling vectors without repmat . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.6 Vectorized use of set on GUI objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6 Going Further 16 MATLAB is a popular programming language for its simplicity and broad range of tools for topics like signal processing, statistics, di erential equations, and of course, matrices. Users can easily add their own m- le functions for speci c applications, further extending MATLAB's usefulness. However, the MATLAB programming language is parsed { code is interpreted and translated into com- puter operations in realtime { where faster languages like C/C++ are compiled ahead of time into the computer's native language. Some advantages to parsing in realtime are greater platform independence, robustness, and easier debugging. (Also note that MATLAB's \eval" function has no C++ equivalent.) The disadvantage of parsing in realtime is signi cant loss in speed, as well as increased overhead and less low-level control....
View Full 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 / 17

Writing_Fast_MATLAB_Code - Writing Fast MATLAB Code Pascal...

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

View Full Document
Ask a homework question - tutors are online