View License

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

» Watch video

Highlights from
Grouping of 2 function

2.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.21 KB File ID: #37141 Version: 1.0

Grouping of 2 function


Alex Dytso (view profile)


Function that generates all possible groups of 2

| Watch this File

File Information

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

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
15 Jun 2012 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.

Comment only
15 Jun 2012 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.
% ans = 1

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

NCHOOSE2 can be found here:

Comment only
15 Jun 2012 Jos (10584)

Jos (10584) (view profile)

Contact us