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

9 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2019-10-20
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?

请先登录,再进行评论。

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-10-20
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

类别

Help CenterFile Exchange 中查找有关 Functions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by