Make a matrix of different combinations.

조회 수: 2 (최근 30일)
C Zeng
C Zeng 2012년 6월 24일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2012년 6월 24일
  댓글 수: 1
C Zeng
C Zeng 2012년 6월 25일
Thanks, I think I find another way to do it, define a 3-dimensional matrix. Thanks.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2012년 6월 25일
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);

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by