Download MATLAB C Math Library 2.0 User's Guide

Transcript
Overview
An index mxArray argument can contain a scalar, vector, matrix, or the result
from a call to the special function mlfCreateColonIndex().
• A scalar subscript selects a scalar value.
• A subscript with vector or matrix indices selects a vector or matrix of values.
• The mlfCreateColonIndex() index, which loosely interpreted means ‘‘all,’’
selects, for example, all the columns in a row or all the rows in a column.
You can also use the mlfColon() function, which is patterned after the
MATLAB colon operator, to specify a vector subscript. For example,
mlfColon(mlfSclar(1), mlfScalar(10), NULL) specifies the vector
[ 1 2 3 4 5 6 7 8 9 10 ].
Note You cannot index into an array with more dimensions than the array
has, although you can use fewer dimensions.
Tip for-loops provide an easy model for thinking about indexing. A
one-dimensional index is equivalent to a single for-loop; a two-dimensional
index is equivalent to two nested for-loops. The size of the subscript
determines the number of iterations of the for-loop. The value of the subscript
determines the values of the loop iteration variables.
Array Storage
MATLAB stores each array as a column of values regardless of the actual
dimensions. This column consists of the array columns, appended top to
bottom. For example, MATLAB stores
A = [2 6 9; 4 2 8; 3 0 1]
5-5