Code covered by the BSD License
12 Jun 2012
Function that generates all possible groups of 2
Watch this File
One of the simple combinatorial task is to create groups out of the given elements. This function creates groups all possible groups of 2.
Thank you for your response. This is exactly the reason why I made this post. In my opinion MatLab needs a better combinatorial package. So stimulating discussion on it is very important in my opinion.
This functionality is already provided by the generic matlab function NCHOOSEK. See NCHOOSE2 for a very fast implementation of nchoosek with k =2, that does the same is submission, but much faster:
tic ; A = group(1:500) ; toc ;
% Elapsed time is 11.030943 seconds.
tic ; B = nchoose2(1:500) ; toc ;
% Elapsed time is 0.014382 seconds.
% ans = 1
This submission Group uses a nested for-loop without pre-allocation making it quite slow.
NCHOOSE2 can be found here: