Average matrices in a cell array within a structure Matlab
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a structure AVG of size 1 x 6 which has one field averageNEST that is a cell array also of size 1 x 6.
Each averageNEST contains matrices of varying sizes (in one dimension), so for example
AVG(1).averageNEST{1,1} is of size 281 x 3 x 19 and
AVG(1).averageNEST{1,2} is of size 231 x 3 x 19
The 2nd and 3rd dimensions of the matrices are always 3 and 19, it is only the first dimension that can change.
I want to average over all the matrices contained within AVG(1).averageNEST and obtain one matrix of size X x 3 x 19 where X is the size of the smallest matrix in AVG(1).averageNEST.
Then I want to do this for all 6 averageNEST in AVG - so have a separate averaged matrix for AVG(1), AVG(2) ... AVG(6).
I have tried multiple things including trying to concatenate matrices using the following code:
for i=1:6
min_epoch = epoch + 1;
for ii=1:19
averageNEST(:,:,ii) = [AVG(i).averageNEST(1:min_epoch,:,ii)];
end
end
and then average this but it doesn't work and now I'm really confused about what I'm doing!
Can anyone help?
3 个评论
Bob Thompson
2018-2-20
Are the values being averaged really just the two consecutive arrays, or are you doing so for all six averageNEST arrays?
I'm sure Stephen could come up with something better, but I would just run a series of for loops.
for I = 1:size(AVG) % Loops through all AVG
for J = 1:size(averageNEST{1},3) % Loops through third dimension
for K = 1:size(averageNEST{1},2) % Loops through second dimension
average = mean(AVG(I).averageNEST{:}(1:min(size(averageNEST{:},1)),K,J);
end
end
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!