How to get mean across cell array of arrays different size?
조회 수: 1 (최근 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
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
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 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!