Matlab matrix indexing

broken image
broken image

The subscript indices can also be vectors. Accessing the element located at second row and third column > x(2,3)

broken image

The two dimensional array elements are accessed with two subscript indices like x(i,j) – where ‘i’ represents row and ‘j’ represents column. Replacing the values of ‘x’ at position with 40 > x() = 40Ĥ0 11 6 8 14 3 18 -6 0 40 Two dimensional Arrays: > x=magic(4) %Create a magic array with 4x4 elements Replacing specific elements with a same value. Replacing the values of ‘x’ at positions with new values > x()= Replacing specific elements in the array by placing the new values on the right side of the expression. Selecting from fifth element to the end > x(5:end) Selecting all elements except the last element > x(1:end-1)

broken image

You can do arithmetic on the ‘end’ operator. To refer the last element of the matrix x use ‘end’ operator > x(end) Making a new vector by swapping two halves of the vector x > x() Select a range of elements using ‘:’ operator.Įxample: Select elements with index ranging from 1 to 5. Let’s review indexing techniques in Matlab: Indexing one dimensional array, two dimensional array, logical indexing, reversiong a vector – are covered.Ĭonsider a sample vector in Matlab.

broken image