简体   繁体   中英

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; What is the fastest way to do this? Thanks, 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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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