Hey all, I have a cell array of (5x3) (Vel{k,l}) and each contains 20000x4 matrix. I'd like to get mean value of cell arrays over the each column.At the end I should have 1x3 cell with 20000x4 matrix. I've searched the previous questions but couldn't figure it out. Thanks in advance.
%M_all{k,l}=mean(Vel{k,l},3);
cellfun(@mean,Vel{k,l});

 채택된 답변

Image Analyst
Image Analyst 2021년 7월 17일
편집: Image Analyst 2021년 7월 17일

0 개 추천

Then maybe just try a simple for loop. Untested code:
[rows, columns] = size(Vel);
averageArray = cell(1, columns);
for col = 1 : columns
sumArray = zeros(rows, columns);
for row = 1 : rows
thisArray = Vel{row, col};
sumArray = sumArray + thisArray;
end
averageArray{col} = sumArray / rows;
end

댓글 수: 5

mehtap agirsoy
mehtap agirsoy 2021년 7월 18일
Thanks for the help. sumArray creates 3x2 zero matrix but thisArray is 20000x4 so matrix dimensions do not agree. I got your idea but couldn't fix my code.Attached is my code if you're able to quide me I'd be glad. Thanks in advance
Image Analyst
Image Analyst 2021년 7월 18일
Attach Vel in a .mat file also.
mehtap agirsoy
mehtap agirsoy 2021년 7월 18일
Attached you can find it. I'm glad, thanks.
This works:
% Setup to get Vel.
s = load('Vel.mat')
Vel = s.Vel;
% Now we have Vel and we can start.
[rows, columns] = size(Vel)
[rows2, columns2] = size(Vel{1,1})
averageArray = cell(1, columns);
for col = 1 : columns
sumArray = zeros(rows2, columns2);
for row = 1 : rows
thisArray = Vel{row, col};
[rows2, columns2] = size(thisArray);
fprintf('The cell of Vel at row %d, column %d contains an array that is %d rows by %d columns.\n',...
row, col, rows2, columns2);
sumArray = sumArray + thisArray;
end
averageArray{col} = sumArray / rows;
end
mehtap agirsoy
mehtap agirsoy 2021년 7월 18일
Million thanks,I was stucked and you really saved my life I really appreciate

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2021년 7월 17일

댓글:

2021년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by