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일

1 개 추천

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(:)]

댓글 수: 2

Le Xuan Thang
Le Xuan Thang 2020년 12월 21일
Thank you, so much
Ameer Hamza
Ameer Hamza 2020년 12월 22일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2020년 12월 21일

댓글:

2020년 12월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by