concatenating the several matrices in a certain manner

2 次查看(过去 30 天)
Hello all,
I have N J matrices all with the same size. I would like to concatenate them in a way such that I would get a new matrix C with its first J columns be the first row of the J matrices, the second J columns of C consist of second column of all the J matrices and so on. For instance suppose J=2 and I have the following two matrices: s1=[0 0 1 1;1 1 0 0;1 1 0 0;0 0 1 1]; s2=[0 0 -1 -1;-1 -1 0 0;-1 -1 0 0;0 0 -1 -1]; I would like to have C=[0 0 0 0 1 -1 1 -1;1 -1 1 -1 0 0 0 0;1 -1 1 -1 0 0 0 0;0 0 0 0 1 -1 1 -1]; I would appreciate any help!

采纳的回答

Stephen23
Stephen23 2015-11-9
编辑:Stephen23 2015-11-9
>> s1=[0 0 1 1;1 1 0 0;1 1 0 0;0 0 1 1]
s1 =
0 0 1 1
1 1 0 0
1 1 0 0
0 0 1 1
>> s2=[0 0 -1 -1;-1 -1 0 0;-1 -1 0 0;0 0 -1 -1]
s2 =
0 0 -1 -1
-1 -1 0 0
-1 -1 0 0
0 0 -1 -1
>> C = [];
>> C(:,2:2:8) = s1;
>> C(:,1:2:8) = s2
C =
0 0 0 0 -1 1 -1 1
-1 1 -1 1 0 0 0 0
-1 1 -1 1 0 0 0 0
0 0 0 0 -1 1 -1 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by