Code covered by the BSD License  

Highlights from
Grouping of 2 function

2.0

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

Grouping of 2 function

by

 

Function that generates all possible groups of 2

| Watch this File

File Information
Description

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

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.

15 Jun 2012 Jos (10584)

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

15 Jun 2012 Jos (10584)  

Contact us