Filter löschen
Filter löschen

How to calculate Mean of unequal cell arrays?

2 Ansichten (letzte 30 Tage)
Vishvendra Bhanu
Vishvendra Bhanu am 29 Mai 2018
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?

Antworten (1)

KSSV
KSSV am 30 Mai 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) ;
  2 Kommentare
Vishvendra Bhanu
Vishvendra Bhanu am 30 Mai 2018
I believe I couldn't explain my question properly. Through this code we can get the mean of all response values stored in one column for e.g.: M(5) = mean of all values stored in DRIFT{5}. I do not want this. I want the geomean of all the values stored in the same row of all drifts - DRIFT{i}. Each DRIFT{i} is a column vector of different length. I want to find the geomean of cells corresponding to the same row number of these column vectors. Geomean() will be a column vector itself.
Vishvendra Bhanu
Vishvendra Bhanu am 30 Mai 2018
So, just to explain more: DRIFT{1,1} is a 14*1 double, DRIFT{1,2} is 17*1 double, DRIFT{1,3} is 27*1 double... and so on. I have some idea on how to find the geomean: I wish to store all these different column vectors (that is each DRIFT{1,i}) in one double matrix of size (j,44). where j is the size of the largest column vector in DRIFT. As each column is of a different size, I want to fill the blank cells with NaN and then replace with 1 (as 1 has no effect on geomean). Could you help me now?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by