Use combvec for pairs of values

1 visualizzazione (ultimi 30 giorni)
Lucas campos
Lucas campos il 30 Ott 2021
Risposto: DGM il 30 Ott 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

Risposte (2)

M.MUSBA Elhadid
M.MUSBA Elhadid il 30 Ott 2021
a = repmat(a,2,4);

DGM
DGM il 30 Ott 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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by