在matlab中从4D数组中提取二维数组

时间:2016-02-05 13:44:09

标签: arrays matlab

我在matlab中有一个像这样的4D数组,

test(:,:,1,1) =

     0


test(:,:,2,1) =

     0


test(:,:,3,1) =

     0


test(:,:,4,1) =

     0


test(:,:,5,1) =

     0


test(:,:,1,2) =

     0


test(:,:,2,2) =

     0


test(:,:,3,2) =

     0


test(:,:,4,2) =

     0


test(:,:,5,2) =

     0


test(:,:,1,3) =

     0


test(:,:,2,3) =

     0


test(:,:,3,3) =

     0


test(:,:,4,3) =

     0


test(:,:,5,3) =

     0


test(:,:,1,4) =

     0


test(:,:,2,4) =

     0


test(:,:,3,4) =

     0


test(:,:,4,4) =

     0


test(:,:,5,4) =

     0


test(:,:,1,5) =

     0


test(:,:,2,5) =

     0


test(:,:,3,5) =

     0


test(:,:,4,5) =

     0


test(:,:,5,5) =

     0

K>> test

test(:,:,1,1) =

     0


test(:,:,2,1) =

     0


test(:,:,3,1) =

     0


test(:,:,4,1) =

     0


test(:,:,5,1) =

     0


test(:,:,1,2) =

     0


test(:,:,2,2) =

     0


test(:,:,3,2) =

     0


test(:,:,4,2) =

     0


test(:,:,5,2) =

     0


test(:,:,1,3) =

     0


test(:,:,2,3) =

     0


test(:,:,3,3) =

     0


test(:,:,4,3) =

     0


test(:,:,5,3) =

     0


test(:,:,1,4) =

     0


test(:,:,2,4) =

     0


test(:,:,3,4) =

     0


test(:,:,4,4) =

     0


test(:,:,5,4) =

     0


test(:,:,1,5) =

     0


test(:,:,2,5) =

     0


test(:,:,3,5) =

     0


test(:,:,4,5) =

     0


test(:,:,5,5) =

     0

现在我想得到一个像这样的数组

ans =

     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0

是否有一种简单的方法来转换维度。 我对Matlab中的多维数组非常陌生。 如果有人知道任何解决方案,请告诉我。

1 个答案:

答案 0 :(得分:1)

使用squeeze函数,当您输入大小为[1 1 5 4]

的矩阵时,它将返回一个大小为[5 4]的矩阵