Programming Previous page   Next Page

Matrix Indexing

This section explains how to use subscripting and indexing to access and assign values to the elements of a MATLAB matrix. It covers the following:

Accessing Single Elements

To reference a particular element in a matrix, specify its row and column number using the following syntax, where A is the matrix variable. Always specify the row first and column second:

For example, for a 4-by-4 magic square A,

you would access the element at row 4, column 2 with

For arrays with more than two dimensions, specify additional indices following the row and column indices. See the section on Multidimensional Arrays.

Previous page  Combining Unlike Data Types Linear Indexing Next page

© 1994-2005 The MathWorks, Inc.