Search code examples
arraysimagematlabmultidimensional-arraycell-array

Dividing a 4D array image data into cells


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.


Solution

  • The function num2cell should work for this, along with a call to reshape afterwards. Starting with your data in a matrix called data:

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