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
以及行索引row1
和row2
:
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.