generate k-ary sequence
6 ビュー (過去 30 日間)
古いコメントを表示
Hey all, I want to thanks the people who helped me on the binary sequences. Now, I am in a difficult position to figure out a k-ary sequence. A k-ary sequence is one in which every element is an integer from 0,1,...,k-1. For example,{2,2,0,1,1,3,3,3,2,3} is a 4-ary sequence. The elements in 4-ary sequence are randomly spotted. Therefore, I want to print out all the possible combinations. I am new to the matlab, could anyone help me to figure out how to code this?
3 件のコメント
Image Analyst
2014 年 11 月 30 日
Do you want to save a combination that does not appear, but that could appear, for example (using 0,1,2,3) you might have a combination of (1,2,3) but you don't have that in the data, or you might have a combination of (3,2,1,1,2,3,3,2) but you don't.
If you're allowing sequences that don't actually occur in the data, how long can these sequences be? Any length from 1 up to the length of the array, or even longer???
採用された回答
その他の回答 (1 件)
Star Strider
2014 年 11 月 30 日
This seems to do what you want:
k = 4;
s = perms([0:k-1]);
4 件のコメント
Star Strider
2014 年 11 月 30 日
編集済み: Star Strider
2014 年 11 月 30 日
There may be as many as 4^10 = 1048576 such unique sequences, so get another several reams of paper and a dozen or more ink or toner cartridges first.
I limited my results to 210 to demonstrate that there were no repeats in that number of sequences.
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!