MATLAB: Generate list of 2 digit combinations without repetition

no repetitionnpermutekpermutation

I'm trying to generate a list of unique 2 digit number combinations from 0 to 9 without repetition. Using npermutek:
a = npermutek(0:9,2)
% OUTPUT:
% a =
%
% 0 0
% 0 1
% 0 2
% 0 3
% 0 4
% 0 5
% 0 6
% 0 7
% 0 8
% 0 9
% 1 0 <-- Repetitive
% 1 1
% 1 2
% 1 3
% 1 4
% 1 5
% 1 6
% 1 7
% 1 8
% 1 9
% 2 0
% 2 1 <-- Repetitive
% ... ...
% 9 9
However I want to filter out the repetitive number combinations like e.g. 10 and 21, since they fall into the same category as 01 and 12 respectively. nchoosek(0:9,2) does not suit my needs as numbers like 00, 11 … are not represented.

Best Answer

I suspect [2 0] meets your standard for being repetitive as well? I'm assuming yes, otherwise the definition seems arbitrary.
If so, the trick is to notice that any value in the second column that is less than the value in the first column would create a repeat value. Using nested for loops, you could use the value of the outer loop to set the starting point for the inner loop.
C=[];
for a = 0:9
for b = a:9
C=[C;a b];
end
end
% visualize the bottom 10 rows of the array
C(end-9:end,:)
ans = 10×2
6 6 6 7 6 8 6 9 7 7 7 8 7 9 8 8 8 9 9 9