How to find all the possible permutations in a given array?
조회 수: 2 (최근 30일)
이전 댓글 표시
Manas Ranjan Pattnayak
2018년 10월 14일
댓글: Manas Ranjan Pattnayak
2018년 10월 14일
The following vector is x = [1 ; 2 ; 3 ; 4 ; 8 ];
I want to find all possible permutations of the given vector by taking 5 elements, 4 elements & 3 elements at a time. The 'perms' function only provides the permutations by taking all the elements of the array at a time.
Kindly suggest any predefined function or process to get this.
댓글 수: 0
채택된 답변
Bruno Luong
2018년 10월 14일
x = [1 ; 2 ; 3 ; 4 ; 8 ]
p=arrayfun(@(k) num2cell(nchoosek(x,k),2), 3:length(x), 'unif', 0);
p=cat(1,p{:});
p=cellfun(@(x) num2cell(perms(x),2),p,'unif',0);
p=cat(1,p{:});
p{:}
댓글 수: 3
Bruno Luong
2018년 10월 14일
편집: Bruno Luong
2018년 10월 14일
- The first command select subsets of 3,4,5 elements from x.
- The second command put the nested cell in the same level
- The third command find permutations of each subset
- The fourth command is similar than the second one
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!