필터 지우기
필터 지우기

If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

조회 수: 2 (최근 30일)
If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

채택된 답변

Guillaume
Guillaume 2017년 5월 31일
Most likely there's already an implementation on the FileExchange. Otherwise, it's easy to implement:
elements = [1 2 3];
count = 6;
combs = cell(1, count);
[combs{:}] = ndgrid(elements);
combs = reshape(cat(count + 1, combs{:}), [], count)

추가 답변 (1개)

ES
ES 2017년 5월 31일
perms
example:
perms(repmat([1 2 3], 1,2))

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by