How to calculate Mean of unequal cell arrays?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
KSSV
on 30 May 2018
% 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) ;
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!