Use combvec for pairs of values

2 ビュー (過去 30 日間)
Lucas campos
Lucas campos 2021 年 10 月 30 日
回答済み: DGM 2021 年 10 月 30 日
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

回答 (2 件)

M.MUSBA Elhadid
M.MUSBA Elhadid 2021 年 10 月 30 日
a = repmat(a,2,4);

DGM
DGM 2021 年 10 月 30 日
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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by