Suvidha
Suvidha

Reputation: 459

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.

Upvotes: 1

Views: 249

Answers (2)

Zep
Zep

Reputation: 1576

This also works, and I find slightly more readable. I tested it and it takes exactly the same time to run.

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

squeeze function removes singleton dimensions. I tested its running time and it is the same as reshaping.

Upvotes: 1

gnovice
gnovice

Reputation: 125854

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, []);

Upvotes: 1

Related Questions