フィルターのクリア

Combination of numbers with specific order

3 ビュー (過去 30 日間)
Fayyaz
Fayyaz 2017 年 10 月 13 日
コメント済み: Fayyaz 2017 年 10 月 13 日
Hi all,
I would like to create a matrix of combination of numbers (with five columns). The number are: 4,6,8,10,12,14
The matrix should be like this:
4 4 4 4 4
4 4 4 4 6
4 4 4 6 6
.
.
.
.
14 14 14 14 14
Please help me out!
  3 件のコメント
Fayyaz
Fayyaz 2017 年 10 月 13 日
編集済み: Walter Roberson 2017 年 10 月 13 日
Many thanks for the comment. Your comment made me think about it. I was a bit vague. Please see the attached.
4 4 4 4 4
4 4 4 4 6
4 4 4 6 6
4 4 6 6 6
4 6 6 6 6
4 4 4 4 8
4 4 4 8 8
4 4 8 8 8
4 8 8 8 8
4 4 4 4 10
4 4 4 10 10
4 4 10 10 10
4 10 10 10 10
4 4 4 4 12
4 4 4 12 12
4 4 12 12 12
4 12 12 12 12
4 4 4 4 14
4 4 4 14 14
4 4 14 14 14
4 14 14 14 14
6 6 6 6 8
6 6 6 8 8
6 6 8 8 8
6 8 8 8 8
6 6 6 6 10
Walter Roberson
Walter Roberson 2017 年 10 月 13 日
Probably a couple of for loops is the easiest way to handle it.

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 10 月 13 日
編集済み: Andrei Bobrov 2017 年 10 月 13 日
out = nchoosek(kron(4:2:14,ones(1,5)),5);
or
x = kron(4:2:14,ones(1,5));
out = hankel(x(1:end-4),x(end-4:end));
  2 件のコメント
Fayyaz
Fayyaz 2017 年 10 月 13 日
Dear Andrei, many thanks.
It works but there is a small problem. I got this matrix (with a number of repetitions):
4 4 4 4 4
4 4 4 4 6
4 4 4 4 6
4 4 4 4 6
4 4 4 4 6
4 4 4 4 6
4 4 4 4 8
4 4 4 4 8
4 4 4 4 8
4 4 4 4 8
4 4 4 4 8
Any recommendation how would I be able to get a unique sequence like:
4 4 4 4 4
4 4 4 4 6
4 4 4 6 6
Thanks in advance.
Andrei Bobrov
Andrei Bobrov 2017 年 10 月 13 日
See my answer: part after word "or".

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 10 月 13 日
Slightly vectorized:
V = 4 : 2 : 14;
num_V = length(V);
pattern = [1 1 1 1 2;
1 1 1 2 2;
1 1 2 2 2;
1 2 2 2 2];
num_pattern = size(pattern,1);
nrow = num_pattern * (num_V - 1) + 1;
out = zeros(nrow, 5);
out(1, :) = V(1);
for idx = 2 : num_V
pair = [V(1), V(idx)];
this_set = pair(pattern);
start = 1 + (idx-2) * num_pattern;
out(start + 1 : start + num_pattern, :) = this_set;
end
  1 件のコメント
Fayyaz
Fayyaz 2017 年 10 月 13 日
Many thanks. It works perfectly. I have already written manually since it was not that long. However, for my next enumeration, I will keep this handy!!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by