Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矩阵,我想找到一个列,该列在 row1 == x 中有项目,在 row2 == y 中有项目;最快的方法是什么?谢谢,CP
考虑:
colIdx = all( bsxfun(@eq, M([row1 row2],:), [x;y]) );
如果您想匹配多于两行,这很灵活
这应该适用于给定的矩阵M和行索引row1和row2:
M
row1
row2
columnIndices = find((M(row1,:) == x) & (M(row2,:) == y));