How to find all the possible permutations in a given array?

2 ビュー (過去 30 日間)
Manas Ranjan Pattnayak
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.

採用された回答

Bruno Luong
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
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
Manas Ranjan Pattnayak
Manas Ranjan Pattnayak 2018 年 10 月 14 日
Thank you so much for the quick response.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by