Change an array by removing all rows that have a particular value in a particular column

Suppose I have an row x col array, called A, for example.

In column 10, say, there are many different values. Some of these are 0. How do I change A so that all rows that contain 0 in column 10 are deleted?

  • Find all rows that are non-zero in that column using e.g. rows_to_keep = findall(...)
  • Create a new matrix without those rows by indexing, e.g. A[rows_to_keep, :]
  • Note, you cannot change the shape of an existing matrix.
2 Likes

Try

rows_to_keep = A[:,10] .!= 0
2 Likes