필터 지우기
필터 지우기

How to find all possible combination of a digits between first and last digits?

조회 수: 2 (최근 30일)
I have points as 1, 2, 3, 4, 5. The point 1 is the first point, and 5 the last point.
I need to find all possible combination of the possible points between 1 and 5.
I need a result like this:
1 5
1 2 5
1 3 5
1 4 5
1 2 3 5
1 3 2 5
1 2 4 5
1 4 2 5
1 3 4 5
1 4 3 5
1 2 3 4 5
1 3 2 4 5
Ect.
Could anyone help me? Thank you!

채택된 답변

Image Analyst
Image Analyst 2016년 7월 10일
Use the perms() function. It sounds a lot like homework. Is it? So here is part of it, the part with all the indexes in there:
m = 1 : 5
indexes = perms([2:4])
m2 = zeros(size(indexes, 1), size(m, 2)) % Initialize output.
for k = 1 : length(indexes)
m2(k,:) = [m(1), m(indexes(k,:)), m(end)];
end
m2 % Print output to command window.
See if you can add the rest to do it for lesser number of indexes.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by