Effacer les filtres
Effacer les filtres

concatenating the several matrices in a certain manner

2 vues (au cours des 30 derniers jours)
Mnr
Mnr le 9 Nov 2015
Modifié(e) : Stephen23 le 9 Nov 2015
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!

Réponse acceptée

Stephen23
Stephen23 le 9 Nov 2015
Modifié(e) : Stephen23 le 9 Nov 2015
>> 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by