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

删除回忆录丶 提交于 2019-12-12 01:57:56

问题


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?


回答1:


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, :)


来源:https://stackoverflow.com/questions/27226622/subsetting-rows-from-matlab-for-which-specific-column-has-value-greater-than-zer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!