Dividing a 4D array image data into cells

时间:2017-06-19 13:59:12

标签: arrays image matlab multidimensional-array cell-array

I have 22000 cell nuclei images which i have stored as a 4D data. Each image is of dimensions 27 by 27 by 3 and they are stored in nuclei4DArrayData as [27 27 3 22000]

Now I want to split this 4D Array into cells such that I have 1x22000 cell array in which each cell has 27x27x3 image data matrix.

I have tried using mat2cell, num2cell but I cannot get the dimension parameter to split it in a way I require. I could manually assign each image to a cell array using the for loop but, is there any direct method or am not able to use the mat2cell function. Just want to know if it is possible using the MATLAB functions.

2 个答案:

答案 0 :(得分:1)

函数num2cell应该适用于此,以及之后调用reshape。从名为data的矩阵中的数据开始:

cellData = reshape(num2cell(data, 1:3), 1, []);

答案 1 :(得分:1)

这也有效,我发现稍微有点可读性。我测试了它,并且运行时间完全相同。

 data = zeros(27, 27, 3, 22000);
 cellData = squeeze(num2cell(data, 1:3));

squeeze函数删除单个维度。我测试了它的运行时间,它与重塑相同。