
position (2,1) is taken to be the second (2), the (3,1) the third and finally the
(m, n) element is the last one (n*m). View the following example to
understand this king of matrix indexing.
Matlab’s command:
>> H=magic(4), H(1), H(2), H(9), H(16)
Matlab’s response:
H =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
ans =
16
ans =
5
ans =
3
ans =
1
Comments:
Extracting specific elements from a matrix using single indexing.
For matrices, the colon notation “:” plays an important role. Colon can be
used to extract either a specific part of a matrix, or to view a whole row, a
whole column or a sub-matrix extracted from the original one. Earlier, the
colon was used to define vectors and it has been explained that it creates
elements from a starting_value through a finishing_value equally spaced
according to a defined step (if the step is not defined, then the step is taken
to be 1). In Matlab, a certain row of a matrix can be extracted by placing the
colon in the row_index, “K(:,column_index)”, and a certain column by placing
the colon in the column_index, “K(row_index:,:)”. A sub-matrix that is
composed by the r1 to r2 rows (r1=r2) and c1 to c2 columns (c1=c2) of the
original matrix can be retrieved according to the following syntax:
“K(r1:r2, c1:c2)”
Comentários a estes Manuais