How to get mean across cell array of arrays different size?

3 visualizzazioni (ultimi 30 giorni)
Dear All, need your help ;) !
I have 1x5 cell array of arrays different size, like this :
myData = {{9×119×11},{6×119×11},{8×119×11},{9×119×11},{7×119×11}}
Across all of them , I need to find one avarage Array , like this : avrData = {9×119×11} .
I have tried next one (seebelow), but doubt if this is correct???
Thanks in advance!
myData = {{9×119×11},{6×119×11},{8×119×11},{9×119×11},{7×119×11}}
% with NaN I make the same size
for k = 1:length(myData)
m = size(myData{k},1);
myDatal{k}(m+1:9,:,:) = NaN; % with NaN I make the same size
end
% I summarize all of new Arrays
sum = myData{1};
for i = 2:length(myData)
sum = sum + myData{i};
end
% here is mean
meanData = sum ./ length(myData));
  1 Commento
Guillaume
Guillaume il 20 Ott 2019
Does it even make sense to pad the shorter matrices with NaN. Why is it row 6 or the 1st array that is averaged with row 6 of the 2nd array and not for example row 8 of the first array?
You're padding at the end but you could be padding at the beginning or evenly either side. All of these would give you different result, so why is padding at the end chosen?

Accedi per commentare.

Risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 20 Ott 2019
Might be following example help you
cell1=rand(3,3,3);
cell2=rand(2,3,2);
cell3=randi(10,2,2)
data={cell1,cell2,cell3}; % Just an example
avg_data=zeros(1,length(data));
for i=1:length(data)
data1=data{i};
data1=data1(:);
avg_data(i)=mean(data1);
end
avg_data

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by