How to find the average of 3D matrices in a cell?
5 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I wish to average the 3D matrices in a cell array?
Each is a 2048 by 2048 by 100 matrix, which looks like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1216082/image.png)
What I wish is to average each 3D matrix over the z axis (over 100), as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1216087/image.png)
This will eventually lead to 1 by 3 cell, but this time, only 2048 by 2048 pixels.
The code that I have used is as follows:
for iB=1:numel(B)
meanB{iB}=mean(B{iB},3); % B is the 3D matrix
end
I have cross-cheked the values, but have found that I am not getting the right values. They are much smaller than expected.
Can anyone please help with this?
Kind regards,
Anshul
0 个评论
回答(1 个)
Walter Roberson
2022-12-1
The code you already have should work. Or you could use the more compact
meanB = cellfun(@(b) mean(b,3), B, 'uniform', 0);
If the values are much smaller than expected, then re-check by commanding
format long g
and then examining the contents at the command line (not in the variable browser.)
2 个评论
Walter Roberson
2022-12-2
That looks like it would work to create a 1 x something cell array. K would need to be varying from 1 to 100 .
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!