MATLAB: Selecting min value per row unless min value is repeated in another row.

comparing rowsMATLABmatrixmatrix manipulationmin values per row

Hi, I have a matrix of values shown below. I want to keep the lower value in each row, unless that lower value is repeated in another row of the matrix. For the matrix shown below, the retained values should be 7, 9, 14, 22, 24, 27, 29, 35, 30, 34, 38, and 44. My first thought was the unique function, but that then prevents me from selecting the min value per row. Thanks in advance for the help.
A = [1 2
1 3
2 3
5 6
3 7
2 8
3 8
8 9
5 10
6 10
10 12
11 13
12 15
11 16
13 16
15 20
14 21
22 28
24 31
20 32
27 33
29 34
32 35
30 36
34 42
38 43
40 48
40 49
48 49
44 50];

Best Answer

Set the duplicate values to Inf/NaN, take the minimum of each row, then remove the Inf/NaN values:
>> A = [1,2;1,3;2,3;5,6;3,7;2,8;3,8;8,9;5,10;6,10;10,12;11,13;12,15;11,16;13,16;15,20;14,21;22,28;24,31;20,32;27,33;29,34;32,35;30,36;34,42;38,43;40,48;40,49;48,49;44,50];
>> U = unique(A(:));
>> A(ismember(A,U(histc(A(:),U)>1))) = Inf; % duplicate values -> Inf.
>> V = min(A,[],2);
>> V = V(isfinite(V)) % remove Inf.
V =
7
9
14
22
24
27
29
35
30
42
38
44
This differs from your example output (which contains 34 instead of 42, even though 34 occurs twice).