23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Techniques for Improving Performance<br />

Functions Used in Vectorizing<br />

Some of the most commonly used functions for vectorizing are as follows<br />

Function<br />

all<br />

any<br />

cumsum<br />

diff<br />

find<br />

ind2sub<br />

ipermute<br />

logical<br />

ndgrid<br />

permute<br />

prod<br />

repmat<br />

reshape<br />

shiftdim<br />

sort<br />

squeeze<br />

sub2ind<br />

sum<br />

Description<br />

Test to determine if all elements are nonzero<br />

Test for any nonzeros<br />

Find cumulative sum<br />

Find differences and approximate derivatives<br />

Find indices and values of nonzero elements<br />

Convert from linear index to subscripts<br />

Inverse permute dimensions of a multidimensional array<br />

Convert numeric values to logical<br />

Generate arrays for multidimensional functions and<br />

interpolation<br />

Rearrange dimensions of a multidimensional array<br />

Find product of array elements<br />

Replicate and tile an array<br />

Change the shape of an array<br />

Shift array dimensions<br />

Sort array elements in ascending or descending order<br />

Remove singleton dimensions from an array<br />

Convert from subscripts to linear index<br />

Find the sum of array elements<br />

Preallocating Arrays<br />

for and while loops that incrementally increase, or grow, thesizeofadata<br />

structureeachtimethroughtheloopcan adversely affect performance and<br />

memory use. Repeatedly resizing arrays often requires that <strong>MATLAB</strong> spend<br />

extra time looking for larger contiguous blocks of memory and then moving<br />

the array into those blocks. You can often improve on code execution time by<br />

11-7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!