MATLAB: Calculate the remaining index of the data

indexing

If i have
x= 1 2
3 4
2 5
1 5
is the index of my data. i want to get on remaining of these index but not need index that have i=j i.e [ (1 1) (2 2) (3 3)(4 4)(5 5) and not need fliplr of x i.e [(2 1)(4 3)(5 2)(5 1)]. so i want to the result
result=
1 3
1 4
2 3
2 4
3 5
4 5
that should not contain fliplr of any index.

Best Answer

Here is one way.
x= [1 2
3 4
2 5
1 5];
result = zeros(5*2,2);
ri = 1;
for ii=1:5
for jj = ii+1:5
result(ri,:) = [ii jj];
ri = ri+1;
end
end
isRowToRemove = ismember(result,x,'rows');
result(isRowToRemove,:) = [];
There is certainly a better way to pre-populate the array result with all possible row values than using the loops, but I got lazy.