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

Make a matrix of different combinations.

Asked by C Zeng on 24 Jun 2012

Hello, all,

If we need to make different combinations, like the first three entries among {0,1,2} and the fourth entry is from {0,1,...,1000} how to make this matrix? There should be 3^3*1001 rows for that matrix.

0 Comments

C Zeng

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 24 Jun 2012

1 Comment

C Zeng on 25 Jun 2012

Thanks, I think I find another way to do it, define a 3-dimensional matrix. Thanks.

Walter Roberson
Answer by Andrei Bobrov on 25 Jun 2012

one way

[k1,k2,k3,k4] = ndgrid(0:2,0:2,0:2,0:1000);
out = [k1(:),k2(:),k3(:),k4(:)];

or

cmb = fullfact([3 3 3 1001]); % 'fullfact' from 'Statistics Toolbox'
d = 0:1000;
out = d(cmb);

0 Comments

Andrei Bobrov

Contact us