merging two matrices (cell matrices)

Hi,
I have two Matrices of dimension A=(63x181) and B=(63x181) I wish to get a matrix 'C' which has its first column from A and 2nd column from B. Then 3rd column from A and 4rth Column from B and so on till the end.
So, Matrix C will have 63 rows and 362 columns (181*2). Order of rown should remain the same.
I am using this code but it only writes one row. Doesn't write the full 63 rows of each column.
for m=2:2:362;
n=m-1;
x=m/2;
C{:,n}=A{:,x};
C{:,m}=B{:,x};
end;
Your help will be highly appreciated. I wonder if there is any builtin function like Cat(), vertcat() to for this.
Regards
AMD.

 채택된 답변

Cedric
Cedric 2013년 4월 18일
편집: Cedric 2013년 4월 18일

0 개 추천

The following would be one way if I interpret well your question (which is not completely clear):
C = reshape([A;B], size(A,1), []) ;
It creates a matrix with the following structure:
C = [A(:,1),B(:,1),A(:,2),B(:,2), ..., A(:,181),B(:,181)]

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 4월 18일

0 개 추천

C = zeros(size(A).*[1 2]);
C(:,1:2:end) = A;
C(:,2:2:end) = B;

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

ARS
2013년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by