So if you want all the columns from column 2 to the last column, you can use write the following: > M(2, 2:end) The end keyword will work exactly as if it was the number of the last element in that dimension. MATLAB also provides a shortcut for specifying the last element of a dimension in the form of the end keyword.
For example, the following code will also return the entire second row > M(2, :) To select an entire row (or column), MATLAB provides a shortcut by allowing you just specify. In MATLAB, the vector is more easily created using the colon operator, i.e. For example to get the entire second row, we can specify that we want the first, second and third columns: > M(2, )
You can index multiple elements at once by passing a vector for each coordinate instead of a single number. Moreover, MATLAB indices starts with 1 and not 0 like most programming languages. Note that the order of subscripts is the same as the mathematical convention: row index is the first. The number of subscripts provided exactly matches the number of dimensions M has (two in this example). For example, accessing the element on the second row and third column: > M(2, 3) The most straight-forward method for accessing an element, is to specify its row-column index. These three methods are now explained in more detail using the following 3-by-3 matrix M as an example: > M = magic(3)