Programming Previous page   Next Page

Functions That Control Indexing Style

If you have row-column subscripts but want to use linear indexing instead, you can convert to the latter using the sub2ind function. In the 3-by-3 matrix A used in the previous section, sub2ind changes a standard row-column index of (3,2) to a linear index of 6:

To get the row-column equivalent of a linear index, use the ind2sub function:


Previous page  Linear Indexing Accessing Multiple Elements Next page

© 1994-2005 The MathWorks, Inc.