Combination of numbers with specific order
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 13 Ott 2017
The order is not clear. Is it the rule that the elements must be non-decreasing towards the right? Or at some point would there be (for example) 8 12 6 2 10 ?
Fayyaz
il 13 Ott 2017
Modificato: Walter Roberson
il 13 Ott 2017
Walter Roberson
il 13 Ott 2017
Probably a couple of for loops is the easiest way to handle it.
Risposta accettata
Più risposte (1)
Walter Roberson
il 13 Ott 2017
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 Commento
Fayyaz
il 13 Ott 2017
Categorie
Scopri di più su Interpolation of 2-D Selections in 3-D Grids in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!