matrix_indexing

# matrix_indexing - Digest Article Matrix Indexing in MATLAB...

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
Digest Article: Matrix Indexing in MATLAB MATLAB's colon notation provides an easy way to extract a range of elements from v . v(3:7) % Extract the third through the seventh elements ans = 9 4 2 11 7 Swap the two halves of v to make a new vector. v2 = v([5:8 1:4]) % Extract and swap the halves of v v2 = 2 11 7 14 16 5 9 4 The special end operator is an easy short-hand way to refer to the last element of v . v(end) % Extract the last element ans = 14 The end operator can be used in a range. v(5:end) % Extract the fifth through the last elements ans = 2 11 7 14 You can even do arithmetic using end. v(2:end-1) % Extract the second through the next-to-last elements ans = 5 9 4 2 11 7 Combine the colon operator and end to achieve a variety of effects, such as extracting every k-th element or flipping the entire vector. v(1:2:end)
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 / 8

matrix_indexing - Digest Article Matrix Indexing in MATLAB...

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

View Full Document
Ask a homework question - tutors are online