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
Asked
Active
Viewed 381 times
2 Answers
6
Consider:
colIdx = all( bsxfun(@eq, M([row1 row2],:), [x;y]) );
This is flexible in case you want to match more than two rows

Amro
- 123,847
- 25
- 243
- 454
0
This should work for a given matrix M
and row indices row1
and row2
:
columnIndices = find((M(row1,:) == x) & (M(row2,:) == y));

gnovice
- 125,304
- 15
- 256
- 359