子集Matlab的行,其特定列的值大于零 [英] Subsetting rows from Matlab for which specific column has value greater than zero

查看:161
本文介绍了子集Matlab的行,其特定列的值大于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从第三列中的值大于零的矩阵中对行进行子集化.例如,我有一个矩阵:

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

关于如何在matlab中做到这一点的任何快速建议?

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

推荐答案

简单地为每个要保留的行创建一个逻辑数组,并将其作为索引传递给行:

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

这篇关于子集Matlab的行,其特定列的值大于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆