MATLAB: Finding min values of third column for rows with similar values

min (a) min value in table

Hi,
I have a Table
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
1.0000 0 6.4662
3.0000 0 9.6356
2.0000 0 9.6356
2.0000 1 7
1.0000 1 5
3.0000 1 6
1.0000 1 10
3.0000 1 44
2.0000 1 12
Now, what I want is that find minimum value of third column for the first column with equal value in each loop of second column.
Maybe it is better to see the result what I mean.
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
2.0000 1 7
1.0000 1 5
3.0000 1 6
Really appreciate

Best Answer

>> M = [2.0000,0,3.1971;1.0000,0,3.1971;3.0000,0,6.4662;1.0000,0,6.4662;3.0000,0,9.6356;2.0000,0,9.6356;2.0000,1,7;1.0000,1,5;3.0000,1,6;1.0000,1,10;3.0000,1,44;2.0000,1,2]
M =
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
1.0000 0 6.4662
3.0000 0 9.6356
2.0000 0 9.6356
2.0000 1.0000 7.0000
1.0000 1.0000 5.0000
3.0000 1.0000 6.0000
1.0000 1.0000 10.0000
3.0000 1.0000 44.0000
2.0000 1.0000 2.0000
>> [U,X,Y] = unique(M(:,1:2),'stable','rows');
>> V = accumarray(Y,M(:,3),size(X),@min);
>> A = [U,V]
A =
2.0000 0 3.1971
1.0000 0 3.1971
3.0000 0 6.4662
2.0000 1.0000 2.0000
1.0000 1.0000 5.0000
3.0000 1.0000 6.0000