Calculate mean from a cell array.
24 次查看(过去 30 天)
显示 更早的评论
I am trying to calculate the mean from 1x10 cell array where the array contains matrices of 138x1 dimensions. But the dimensions of all 10 arrays are not the same. So is it possible to calculate mean out of all together the cell arrays having different dimensions? Here I am attaching the file Sum_col.mat from which I want to calculate the mean.
Any help would be really appreciated. Thank you in advance.
0 个评论
采纳的回答
Rik
2021-7-16
Two options of what you could mean:
%load your data first
websave('data.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/686468/Sum_col.mat');
Sum_col=load('data.mat');Sum_col=Sum_col.Sum_col
%mean of each cell (returning a 1x10 array)
cellfun(@mean,Sum_col)
%mean of every element (returning a 138x1 array)
tmp=Sum_col;max_sz=max(cellfun('prodofsize',tmp));
for n=find(cellfun('prodofsize',tmp)<max_sz)
tmp{n}((end+1):max_sz)=NaN; % fill extra entries with NaN
end
mean(cell2mat(tmp),2,'omitnan')
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!