Member-only story

Matlab Basics— How to access array elements based on their position (index) in the array

Marika Lam
Feb 1, 2023

--

Indexing with Element Positions

e is the element in the 3,2 position (third row, second column) of A.

You can also reference multiple elements at a time by specifying their indices in a vector. For example, access the first and third elements of the second row of A.

To access elements in a range of rows or columns, use the colon. For example, access the elements in the first through third row and the second through fourth column of A.

An alternative way to compute r is to use the keyword end to specify the second column through the last column. This approach lets you specify the last column without knowing exactly how many columns are in A.

--

--

No responses yet