I have received an answer from Yvon over on StackOverflow, click link for that question/answer, I will also post here for any googlers.
clear;clc
% create an example struct array
field1 = 'f1'; value1 = rand(1,10);
field2 = 'f2'; value2 = {rand(3,4,2), rand(3,4,2)};
field3 = 'f3'; value3 = {pi, pi.^2};
field4 = 'f4'; value4 = {magic(3), magic(3).^2};
S = struct(field1,value1,field2,value2,field3,value3,field4,value4);
clearvars field* value*
N = length(S);
T = struct();
U = T;
% enumerate over all fields (all should be numbers)
FN = fieldnames(S);
for ii=1:length(FN)
fn = FN{ii};
ss = {S.(fn)};
% convert cell array of N-dim matrices into one (N+1)-dim matrix
ssdim = ndims(ss{1});
TT = cell2mat( reshape(ss, [ones(1,ssdim),N]) );
% here you can do what you want
T.(fn) = mean(TT,ndims(TT));
U.(fn) = var(TT,0,ndims(TT));
end
clearvars ii ssdim ss fn TT
for ii=1:length(FN)
disp(FN{ii})
disp(T.(FN{ii}))
disp(U.(FN{ii}))
end
clearvars ii N
The basic steps are addressed in code comments. TT is 30 trials of one particular type of experimental data. Say you are in the iteration for field pixelLPStats. Each trial has a matrix assigned by this name, which is a 5x2 double array. So, TT will be a 5x2x30 array. You can do what you want with it. Then let the loop bring you to the next field.