I've spent some time researching this, but am likely missing something simple. I have intermediate Matlab knowledge.
I have a structure of data saved from an experiment;
1x30 struct array with fields:
pixelStats: [118.6892 3.1370e+003 -0.1418 2.1195 -25.9308 259.3778]
pixelLPStats: [5x2 double]
autoCorrReal: [9x9x5 double]
autoCorrMag: [4-D double]
magMeans: [18x1 double]
cousinMagCorr: [4x4x5 double]
parentMagCorr: [4x4x4 double]
cousinRealCorr: [8x8x5 double]
parentRealCorr: [8x8x4 double]
varianceHPR: 21.5116
Where each sub-field ('arrays'? terminology is likely incorrect I'm sorry) is a different size. There are 30 entries (trials) that I need to average across so that the shape of the above is retained, but the values for each cell within each field are averaged across the 30 trials. I also need the variance (I am trying to calculate Z scores to see if other trials are significantly different from this population).
First I tried to do this in a for loop, where I get the fieldnames, then for each field I break in and try to add the values for each element across the 30 trials, though this strategy doesn't work for fields with differently sized dimensions (e.g. I'd need to variably create differently sized for loops according to dimensions of current field).
Then I tried to convert the data structure to a cell array, which works;
cell_in = struct2cell(s_params_in)
cell_in = 10x1x30 607440 cell
...and then I tried something I found in my searching that uses cellfun, though to be honest I am not entirely sure of how it works. I had to add the UniformOutput to deal with unequal sized fields.
cellfun( @(cell_in) sum(cell_in(:)), cell_in,'UniformOutput',false)
This summed all values within each 'field' (first dimension), collapsing across elements within them, for all 30 trials. e.g.
ans(:,:,30) =
[3.4911e+003]
[ 10.9414]
[2.0854e+009]
[2.6877e+007]
[1.3612e+004]
[2.3328e+006]
[8.4917e+004]
[7.3826e+008]
[8.2038e+003]
[ 22.4030]
I tried playing around with how I called the cell_in(:) part, but could not get the result I was looking for i.e. an array summed across the dimension for trials, whilst retaining the other dimensionality.
I have also tried to convert that to a matrix and then I could use something like
sum([data(:)])
And play around with reshaping to get the original size back, though that also seems difficult and I'd probably have to do it per fields and manually input the dimensions. The cell2mat doesn't work anyhow on account of the inconsistent dimensions.
So now I'm at the limit of my knowledge and am reaching out for help, can anyone solve this?
Cheers, Alex