How to compute Permutation without repetition?

68 ビュー (過去 30 日間)
Prasanna Rajbhandari
Prasanna Rajbhandari 2016 年 5 月 6 日
コメント済み: aweller3 2021 年 11 月 26 日
We are trying to create a permutation with a,b,c,d,e,f. Taking 5 at a time. We want all the possible permutation without repetition.

採用された回答

Roger Stafford
Roger Stafford 2016 年 5 月 6 日
編集済み: Roger Stafford 2016 年 5 月 6 日
If a, b, c, etc. are different numbers, do this:
v = [a,b,c,d,e,f];
P = perms(v);
P = P(:,1:5);
The matrix P will now contain all possible permutations of five elements selected out of v. There will be 720 rows and 5 columns.
If you had asked for, say, all permutations of five numbers chosen out of a larger number like ten, I would have had to do more work above.
  2 件のコメント
Prasanna Rajbhandari
Prasanna Rajbhandari 2016 年 5 月 6 日
Thank you so much. This really helps me. I have 6 sensors and 5 must be chosen with different possible permutations.
John
John 2017 年 10 月 11 日
This answer assumes the result depends on order, i.e. 12345 is different from 21345. If the result is independent of order than use nchoosek(1:6, 5) which produces the six unique combinations
1 2 3 4 5
1 2 3 4 6
1 2 3 5 6
1 2 4 5 6
1 3 4 5 6
2 3 4 5 6
I think selecting 5 out of 6 sensors would be order independent, e.g. 12345 and 21345 are the same selection.

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

その他の回答 (1 件)

Syed Faheemuddin
Syed Faheemuddin 2018 年 11 月 23 日
Check this function which give all the possible permutations without repetition.
  1 件のコメント
aweller3
aweller3 2021 年 11 月 26 日
It looks great - I will try it out. Thanks!

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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by