Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

need help in random sampling of all possible combinations

Asked by Utpal Bakshi

Utpal Bakshi (view profile)

on 11 Feb 2013

Hi all,

I have an input file (input.txt) in tab separated format. A small part of the input file is as follows:

Gr1 Gr2 Gr3 Gr4    ..............
row1 1 1 1 0       ..............
row2 0 1 0 1       ...............
row3 1 1 0 1       ..............

From this input,random sampling of all possible Group combinations needed to be taken, and print in a output file. From the above input, the output file should be as follows (the three columns are: Number of groups used in analysis, Group names, Number shared between these groups;;; Shared number are measured if 1 is present in all the measuring groups).


2 Gr1-Gr2 2
2 Gr1-Gr3 1
2 Gr1-Gr4 1
2 Gr2-Gr3 1
2 Gr2-Gr4 2 
2 Gr3-Gr4 0
3 Gr1-Gr2-Gr3 1
3 Gr1-Gr2-Gr4 1
3 Gr1-Gr3-Gr4 0
3 Gr2-Gr3-Gr4 0
4 Gr1-Gr2-Gr3-Gr4 0

Any idea how to do it??? thanks in advance..


Utpal Bakshi

Utpal Bakshi (view profile)


No products are associated with this question.

1 Answer

Answer by Youssef Khmou

Youssef Khmou (view profile)

on 11 Feb 2013


You can create a cell in which you can store all your variables (2,Gr2,Gr4,...) (cell because you have heterogeneous data), and then you can obtain all possible combinations by using the function perms :

An example using cell A with 3 elements :

 A{2}='that is you';


Youssef  Khmou

Youssef Khmou (view profile)

Contact us