function repeat number?

2 次查看(过去 30 天)
Hi everyone!
I have a problem like this:
a = [1 2 3]
b = [1 2 3]
and I want matrix combine 2 matrix a and b.
Cuppose,It is matrix C and size of C is 9x2 matrix
C = [ 1 1; 1 2; 1 3
2 1; 2 2; 2 3;
3 1;3 2; 3 3]
Does Matlab have any function like this?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-12-21
编辑:Ameer Hamza 2020-12-21
combvec() from the Deep learning toolbox is most easiest solution
a = [1 2 3]
b = [1 2 3]
C = combvec(a, b).'; % if the order of column is important: C = fliplr(combvec(a, b).');
The other solution is to use ndgrid()
a = [1 2 3]
b = [1 2 3]
[A, B] = ndgrid(a, b);
C = [B(:) A(:)]

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by