tags:

views:

38

answers:

2

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

A: 

This should work for a given matrix M and row indices row1 and row2:

columnIndices = find((M(row1,:) == x) & (M(row2,:) == y));
gnovice
+5  A: 

Consider:

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

This is flexible in case you want to match more than two rows

Amro

related questions