melatonin15
melatonin15

Reputation: 2269

Subsetting rows from Matlab for which specific column has value greater than zero

I want to subset rows from matrix for which the value in third column is greater than zero. For example, I have a matrix :

test =

     1     2     3
     4     5     0
     4     4     1
     4     4     0

Now I want to subset it so that I have

subset  =

     1     2     3
     4     4     1

Any quick suggestion on how I can do this in matlab?

Upvotes: 0

Views: 1528

Answers (1)

Jonas
Jonas

Reputation: 74940

Simply make a logical array that is true for every row you want to keep, and pass it as the index to the rows:

subset = test(test(:,3)>0, :)

Upvotes: 3

Related Questions