MATLAB: How to find maximum without duplicates

duplicateindicesMATLABmaxtie

I have the matrix, A = [1 2 1 0 0 2; 2 1 4 2 0 0; 1 1 0 2 1 1; 1 1 0 1 4 2] I understand that max(A) gives the maximum for each column,but how do I create a logical array locating the maximum of each column? If there is a tie, I just want to consider the first occurrence of the maximum.

Best Answer

A = [1 2 1 0 0 2; 2 1 4 2 0 0; 1 1 0 2 1 1; 1 1 0 1 4 2];
[v, ind] = max(A, [], 1);
Now ind is the row index of the first maximum value per column.
And a "logical array locating the maximum of each column":
siz = size(A);
L = false(siz);
L(sub2ind(siz, ind, 1:siz(2))) = true;