How to calculate Mean of unequal cell arrays?
2 次查看(过去 30 天)
显示 更早的评论
I have results from 44 analyses stored in two cell arrays: 1. DRIFT (the response values) corresponding to INT (intensities). Both are 1*44 cell arrays. For example, the response from 5th analysis is stored in DRIFT{1,5} and the values are corresponding to intensity values in INT{1,5}. I stored the result in cell arrays and not as double because they are of unequal lengths. I want to find the geometric mean of all the 44 responses and plot it. However, as the responses are of different vector lengths (each analysis finish at a different point), I am unable to do so. Could someone help me?
0 个评论
回答(1 个)
KSSV
2018-5-30
% make some random data for demo
N = 10 ;
A = cell(N,1) ;
for i = 1:N
A{i} = rand(randperm(N,1),1) ;
end
%%get mean
N = numel(A) ;
% option 1: use loop
M1 = zeros(N,1) ;
for i = 1:N
M1(i) = mean(A{i}) ;
end
% option 2: use cellfun
M2 = cellfun(@mean,A) ;
另请参阅
类别
在 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!