MATLAB: Find rows in matrix based on columns value

imageimage processingImage Processing ToolboxMATLAB

If i have a matrix:
mat = [1 2 3 4;
5 6 7 8;
9 10 11 12];
How do i find the row index where the column has value 10 and 11 for example? In this case, the row index will be 3 since it has columns with 10 and 11.
I tried doing something like:
find(mat(:,2) == 10 && mat(:,3) == 11)
But it doesn't work.

Best Answer

Hi Steward Tan,
in the given matrix there is no single column that contains the values 10 AND 11. If you want to find the rows that contain 10 AND 11 you could use:
tmp = arrayfun(@(dIn) find(any(mat(dIn,:) == 10) & any(mat(dIn,:) == 11)),1:size(mat,1),'UniformOutput',false);
tmp(cellfun(@isempty,tmp)) = {0};
row = find(cell2mat(tmp));
If you want to find the values 10 OR 11 within the matrix, and return the rows they have been found in, one way might be:
mat = [1 2 3 4;
5 6 7 8;
9 10 11 12];
[row,~] = find(mat == 10 | mat == 11);
row = unique(row);
Kind regards,
Robert