Questions tagged [matrix-indexing]

Indexing into a matrix is a means of selecting a subset of elements from the matrix/array

Matrix indexing is a way to reference a particular element in a matrix, by specifying its row and column number.

The notion extends to multi-dimensional arrays as well.

This is a fundamental concept in many languages such as MATLAB, Octave, Python+NumPy, R, Julia, etc...

There are several matrix-indexing methods:

  • row/column indexing: M(m,n) accesses the element on the m-th row on the n-th column.
  • linear indexing: this methods treats the matrix as a 1D list of elements and access the n-element. Note that there may be several ways of "flattening" the matrix row-first or column-first.
  • logical indexing: by specifying a mask

The use of indexing can often improve performance in the context of code , as it can replace for-loops, if conditions, etc.

302 questions
-2
votes
2 answers

Extracting a 3x3 matrix from an image

I need to extract a 3x3 matrix from an image and store it separately, and it should continue like this till the end of image. For example, my image is the following matrix: p = [ 1 2 3 4 5 6 7 8 9; ... 1 2 3 4 5 6 7 8 9; ... 1 2 3 4 5 6…
-3
votes
1 answer

First half of a vector and even indexed elements

I have this question to which I have a partial answer to. Hope you would help me in doing the rest: Part A: Create a vector of random numbers of size 1×20, and name it as data. The values of these random numbers should be in the range between 0 and…
UMJ
  • 3
  • 1
  • 4
1 2 3
20
21