本文介绍了查找列中具有特定值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Matlab中,我有一个矩阵(MxN),我想查找在特定列中的条目等于指定值的行.例如,我有一个矩阵如下:
In Matlab, i have a matrix (MxN) and I want to find the rows whose entry in a specific column is equal to a specified value. For example, I have a matrix as follow:
0 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 1 0 0 1
0 0 1 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 1 0 1 0
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
我想找到第7个元素等于1
的行.在此示例中,结果矩阵应包含第2行和第7行.
I want to find the rows whose 7th element us equal to 1
. In this example, the result matrix should contains rows 2 and 7.
推荐答案
如果您的矩阵称为A
,请执行以下操作:
if your matrix is called A
, just do:
A(A(:,7)==1,:)
PS:我认为这个问题已经被回答了一百万次了……
PS: I think that this question has already been answered a million times...
这篇关于查找列中具有特定值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!