You are creating a 1x5
struct
array. To quote the struct
documentation:
If
value
is a cell array, thens
is a structure array with the same dimensions asvalue
. Each element ofs
contains the corresponding element ofvalue
.
Since the second argument in the expression struct( 'Ps', cell( 1, length(Ps) ) )
is a 1x5
cell
, the output struct
will be a 1x5
struct
array, and the proper assignment in the for
-loop will be
space_averaged_data(p).Ps = mean( Ps{p}, 2 );
To get the behavior you desire, wrap the second argument in {}
to make it a 1x1
cell
array:
space_averaged_data = struct( 'Ps', {cell( 1, length(Ps) )} );
and the for
-loop should work as expected.