how to make a matrix only showing Permutation without order ?

3 ビュー (過去 30 日間)
Simon Gühring
Simon Gühring 2022 年 10 月 28 日
回答済み: Bruno Luong 2022 年 10 月 29 日
iam currently on projekt calculation every 3 Dart Single Kombination possible but without giving me the same number in a differnt order.
Code
c=[1:20 25]
c = 1×21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25
Single1=c
Single1 = 1×21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25
Single2=Single1;
Single3=Single1;
Singlkomb = fliplr(combvec(Single1,Single2,Single3)')
Singlkomb = 9261×3
1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10
the combination fliplr(combvec(Single1,Single2,Single3)') brings me all the combination e.g 1 2 1, 2 1 1 and 1 1 2 but i only want that the same numbers appears one time in the matrix. I want to find a method that shows me permutation without order.
Thx

採用された回答

Torsten
Torsten 2022 年 10 月 28 日
編集済み: Torsten 2022 年 10 月 28 日
You mean
nchoosek([1:20,25],3)
ans = 1330×3
1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 2 10 1 2 11 1 2 12
nchoosek(21,3)
ans = 1330
not
21^3
ans = 9261
?
  2 件のコメント
Simon Gühring
Simon Gühring 2022 年 10 月 28 日
hey thank you for your answer
no maybe i havn`t expressed myself very well i want as output
1 1 1
1 1 2
1 1 3 and so on
but every kombination should appear just once for example only 1 1 2 and not 1 2 1 or 2 1 1 its about the order.
Torsten
Torsten 2022 年 10 月 28 日
編集済み: Torsten 2022 年 10 月 28 日
c=[1:20 25];
Single1=c;
Single2=Single1;
Single3=Single1;
Singlkomb = fliplr(combvec(Single1,Single2,Single3)')
Singlkomb = 9261×3
1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10
Singlkomb = unique(sort(Singlkomb,2),'rows')
Singlkomb = 1771×3
1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10
nchoosek(21,1)+nchoosek(21,2)*2+nchoosek(21,3)
ans = 1771

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

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2022 年 10 月 29 日
This is called combination with repetition
You don't need to generate the permutation and filter out which can take much larger amount of memory
a=[1:20,25]
a = 1×21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25
k=3
k = 3
c=repcomb(a, k)
c = 1771×3
1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10
%% return combination of k elements of array a with repetition
function c = repcomb(a, k)
n=length(a);
q=n+k-1;
j=nchoosek(1:q,k)-(0:k-1);
c=a(j);
end

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by