Matrix Indexing

  • Indexing involves picking out certain elements within a matrix. For a row or column matrix you simply have to specify the position in the unidirectional sequence. With larger matrices, there’s a need to specify the column and row of the element. Examples of these are seen below:




CHECKPOINT: This is the “end” (No, not really)

What would the following do to the matrices S and M above?

  1. P = M (2 : end, 2 : end)
  2. J = S (4 : end-1)
  3. T = S (end : -1 : 1)

What is the key difference between matrices T and S?


  • Summary on the use of the colon operator, :
Format Purpose
A(:, j) Outputs the jth column of A
A(i, : ) Outputs the ith row of A
A(:, : ) Outputs a two-dimensional array. If A were a matrix, output would be A
A(j : k) Outputs jth to kth elements of A
A(:, j : k) Outputs all the elements  from the jth to kth columns of A
A(:) Outputs all elements of A regarded as a single column
  •  Empty square brackets [ ] are used to delete rows or columns in a matrix e.g. A(:, j) deletes the jth column of matrix A.