Search code examples
matlabmatrixmatrix-indexing

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


Solution

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

    columnIndices = find((M(row1,:) == x) & (M(row2,:) == y));