Mean off cell array for each column
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
mehtap agirsoy
am 17 Jul. 2021
Kommentiert: mehtap agirsoy
am 18 Jul. 2021
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});
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 17 Jul. 2021
Bearbeitet: Image Analyst
am 17 Jul. 2021
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 Kommentare
Image Analyst
am 18 Jul. 2021
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
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!