简体   繁体   English

如何在矩阵中找到与Matlab中的2行匹配的列?

[英]How can I find column in matrix that matches 2 rows in matlab?

I have a matrix, that I want to find a column that has item in row1 == x, and item in row2 == y; 我有一个矩阵,我想找到一列,其中的row1 == x项,而row2 == y项; What is the fastest way to do this? 最快的方法是什么? Thanks, CP 谢谢,CP

Consider: 考虑:

colIdx = all( bsxfun(@eq, M([row1 row2],:), [x;y]) );

This is flexible in case you want to match more than two rows 如果您要匹配两行以上,这是灵活的

这对于给定的矩阵M以及行索引row1row2

columnIndices = find((M(row1,:) == x) & (M(row2,:) == y));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM