a=1 2 3 4 5 6 7 8 9 b=0 1 1 2 3 2 3 2 1 resultant matrix is 1 0 2 1 3 1 4 2 5 3 6 2 7 3 8 2 9 1

4 次查看(过去 30 天)
a=1 2 3
4 5 6
7 8 9
b=0 1 1
2 3 2
3 2 1
How do I interleave columns?
resultant matrix is 1 0 2 1 3 1
4 2 5 3 6 2
7 3 8 2 9 1

回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-10-27
a=[1 2 3; 4 5 6; 7 8 9]
b=[0 1 1; 2 3 2; 3 2 1]
[n,m]=size(a)
c=zeros(n,2*m)
c(:,1:2:end)=a
c(:,2:2:end)=b

Jan
Jan 2014-10-27
a = [1 2 3; 4 5 6; 7 8 9];
b = [0 1 1; 2 3 2; 3 2 1];
c = reshape([a; b], 3, 6)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by