# how to form a two-column array for a given but dimmension-unknown array?

조회 수: 1(최근 30일)
Benson Gou 2021년 6월 9일
편집: Stephen23 2021년 6월 10일
Dear All,
I have two array with the same length A and B. I want to form another array C which is formed by A and B. But the dimmensions of A and B are uncertain, sometimes A (B) is a row vector so that C = [A' B'], but sometimes A (B) is a column vector so that C = [A B].
I am wondering if there is a simple way to form array C without checking the dimmensions of A and B.
Thanks.
Benson

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

### 채택된 답변

Stephen23 2021년 6월 10일
편집: Stephen23 2021년 6월 10일
"I am wondering if there is a simple way to form array C without checking the dimmensions of A and B."
C = [A(:),B(:)]

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

### 추가 답변(1개)

Joel Lynch 2021년 6월 9일
편집: Joel Lynch 2021년 6월 10일
You can make a row vector of any N dimensional matrix by linearizing, for example
A( 1:numel(A), 1 ) = A(:);
.Thus, you can always make
C = C(1:numel(A),1:2) = [ A(:) , B(:) ];
##### 댓글 수: 4표시숨기기 이전 댓글 수: 3
Joel Lynch 2021년 6월 10일
Assuming A and B have the same number of elements, then C=[A(:),B(:)]; should work.
Make sure A, B, and C are cleared and reset before trying this. numel(A) and numel(B) should be the same. And C should not be defined.

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

### Community Treasure Hunt

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

Start Hunting!