A = [1 2 3;3 4 5;5 6 7]
B = [4 5 6;6 7 8;7 8 9]
For I = 1:3
C(:,I) = [A(:,2*I-1) B(:,2*I)]
end
I want C as a matrix whose odd columns will be from A and even columns will be from B. So that output matrix will be 3x6 But this program shows dimension mismatch error.

 채택된 답변

Matt J
Matt J 2014년 10월 19일
편집: Matt J 2014년 10월 19일

0 개 추천

C(:, 2:2:2*size(B,2))=B;
C(:, 1:2:end)=A;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2014년 10월 19일

편집:

2014년 10월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by