Combine columns from different matrix

조회 수: 15 (최근 30일)
zainab hp
zainab hp 2015년 11월 11일
편집: Thorsten 2015년 11월 12일
Hello everyone : I need to combine three arrays
A=[2 4 5; B=[4 6 3; C=[5 2 5;
4 6 8; 2 4 6; 2 4 5;
1 4 7;]; 0 4 5;]; 1 3 5;];
to
output[ 2 4 5 4 6 2 5 3 5;
4 2 2 6 4 4 8 6 5;
1 0 1 4 4 3 7 5 5;]
output[column1 from A , column1 from B , Column1 form C,column2 from A, Column2 from B, colomn2 from c,column 3 from A, ........];

채택된 답변

Star Strider
Star Strider 2015년 11월 11일
A loop is one option:
A=[2 4 5;
4 6 8;
1 4 7;];
B=[4 6 3;
2 4 6;
0 4 5;];
C=[5 2 5;
2 4 5;
1 3 5;];
output = [];
for k1 = 1:3
output = [output A(:,k1) B(:,k1) C(:,k1)];
end
output =
2 4 5 4 6 2 5 3 5
4 2 2 6 4 4 8 6 5
1 0 1 4 4 3 7 5 5
  댓글 수: 2
zainab hp
zainab hp 2015년 11월 12일
Thank you very much ..
Star Strider
Star Strider 2015년 11월 12일
My pleasure.

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

추가 답변 (1개)

Thorsten
Thorsten 2015년 11월 12일
편집: Thorsten 2015년 11월 12일
Or simply reshape
out = reshape(vertcat(A,B,C), 3, [])

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by