File Exchange

image thumbnail

Grouping of 2 function

version 1.0 (1.21 KB) by

Function that generates all possible groups of 2

0 Downloads

Updated

View License

One of the simple combinatorial task is to create groups out of the given elements. This function creates groups all possible groups of 2.

Comments and Ratings (3)

Alex Dytso

Alex Dytso (view profile)

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.

Jos (10584)

Jos (10584) (view profile)

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.
isequal(A,B)
% ans = 1

This submission Group uses a nested for-loop without pre-allocation making it quite slow.

NCHOOSE2 can be found here:
http://www.mathworks.com/matlabcentral/fileexchange/20144

Jos (10584)

Jos (10584) (view profile)

MATLAB Release
MATLAB 7.6 (R2008a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video