Use combvec for pairs of values

2 vues (au cours des 30 derniers jours)
Lucas campos
Lucas campos le 30 Oct 2021
Réponse apportée : DGM le 30 Oct 2021
Hello,
I have a matrix (20 x 2) .
I would like to create 4 possible combinations of each pair of values present on each row of this matrix into a new matrix with 8 columns.
Basically, I would like to use combvec but instead of using scalars, I would be using pairs of values.
Any ideas?
Tnks

Réponses (2)

M.MUSBA Elhadid
M.MUSBA Elhadid le 30 Oct 2021
a = repmat(a,2,4);

DGM
DGM le 30 Oct 2021
If there's only two columns, what's wrong with just doing
A = randi(9,20,2)
A = 20×2
8 4 8 6 7 8 4 1 7 6 3 8 1 5 5 6 1 3 9 5
B = A(:,[1 1 1 2 2 1 2 2])
B = 20×8
8 8 8 4 4 8 4 4 8 8 8 6 6 8 6 6 7 7 7 8 8 7 8 8 4 4 4 1 1 4 1 1 7 7 7 6 6 7 6 6 3 3 3 8 8 3 8 8 1 1 1 5 5 1 5 5 5 5 5 6 6 5 6 6 1 1 1 3 3 1 3 3 9 9 9 5 5 9 5 5

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by