matlab 矩阵合并

matlab 矩阵合并
>> test1=[1,2;3,4]
test1 =
     1     2
     3     4
>> test2=[5,6;7,8]
test2 =
     5     6
     7     8
>> test3=[test1,test2]
test3 =
     1     2     5     6
     3     4     7     8
>> test4=[test1;test2]
test4 =
     1     2
     3     4
     5     6
     7     8
===
对于维数相同的矩阵
cat(1,A,B)相当于[A;B]
cat (2, A, B) 相当于[A,B]
cat (3, A, B) 相当于增加维度
当A,B分别为二维矩阵时,合并之后为三维矩阵;A,B为三维矩阵,则在第三维方向上合并A,B。

>> cat(1,test1,test2)

ans =

     1     2
     3     4
     5     6
     7     8

>> cat(2,test1,test2)

ans =

     1     2     5     6
     3     4     7     8

>> cat(3,test1,test2)

ans(:,:,1) =

     1     2
     3     4


ans(:,:,2) =

     5     6
     7     8

你可能感兴趣的:(matlab 矩阵合并)