Access and manipulations with the data in cell arrays within cell arrays (nested cell arrays)

1 view (last 30 days)
Some measurements are done on images to extract blobs (they are lateral flow strip lines – Test lines and Control lines) in images that are contained in various folders. There are 8 folders, and in each folder, there are 30 images, and in each image, there are either 1 blob(1 line) as in folder 1 or 2 blobs (two lines) as in all other folders.
I am able to extract the blob measurements. (using regionprops)
Further ahead, with some more calculations, I obtained an additional parameter Corrected mean (absolute value of (Mean intensity of the blobs- background mean intensity). (Background is white, so background intensity is around 255 or less)
I intend to get the total mean values of the corrected means of 30 images (of blob1 and blob2 separately) in each folder
As shown below for folder 8….( correctedmeans of 30 images are as follows)
[55.311 , 10.796]
[53.468 , 9.760]
[50.499 , 11.883]
[55.335 , 10.840]
The outcome desired is mean([55.311,…55.335]) and mean([10.796,….10.840]).
The nested cell arrays are too complicated. I have been trying to work on this for quiet sometime but no luck so far.
Anyone Please help! Thanks in advance.
i.e., I would like to caluclate the OVERALL means of:
  1. blob1’s corrected means
  2. blob2’s corrected means
Please see the images attached for reference.
Choosing the 8th folder ( For example) shows inner cells like the following
(NOTE: Any of the above 8 folders will show up SIMILAR cells. I just chose 8th for putting forward my doubt)
I would like to get the mean values of the following deep inner cell arrays
And also the mean values of the following deep inner cell arrays

Accepted Answer

Towfeeq Fairooz
Towfeeq Fairooz on 3 Jun 2021
Edited: Towfeeq Fairooz on 3 Jun 2021
After seeing some posts on cell arrays here in the forum I was able to solve my cell arrays problem. I was able to obtain the mean of inner cell array elements.
Sharing it here in case someone may find it useful. The solution worked for me when I used vertcat(), but the more the inner cells the more the use of vertcat to unnest the cell arrays. I am sure there must be some easy way to solve this. I would appreciate it, if anyone can suggest better ways of doing it.
Alslo please let me know how to use the vectors instead of for loop. I have read at places that using vectors is better than for loop. I would like to how or why is it better .
The code I tried:
clc;
clear all;
load('corMean.mat');
% cnt = count of folders - 8 in this case
% n = number of files in each folder - 30 for now (can vary)
% k = number of blobs in each image - in first folder, n images have 1 blob
% whereas the remaining folders with n images have 2 blobs each.
for cnt=1:size(corMean,2)
for n=1:size(corMean{cnt},1)
for k=1:(size(corMean{cnt},2))
corMeanCat{cnt}{:,k}=[vertcat([corMean{cnt}{:,k}])];
catOf_CorMeanCat{cnt}{k}= [vertcat([corMeanCat{cnt}{k}])];
meanOfAllCorMeans{cnt}{k}=mean([catOf_CorMeanCat{cnt}{:,k}{:}]);
end
end
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by