how can i take average of matrices in a cell?

2 Ansichten (letzte 30 Tage)
Joseph
Joseph am 15 Mär. 2018
Kommentiert: Joseph am 15 Mär. 2018
Hi, i have a cell array X{16*12} in which each element of cell X is a 3d array. now I want to take the average of all the matrices in the row which will result in another cell array Y{1,12} (each element of Y cell array consist of 3d array). can anyone please help me with this.
thank you
  5 Kommentare
Joseph
Joseph am 15 Mär. 2018
Bearbeitet: Joseph am 15 Mär. 2018
Thank you so much Bob, even though your answer wasn't that I wanted, but it gave me the idea how to do it. i was looking for the averaging of the entire matrices in the for each column of the cell X(16,12). which will result in another cell like resultcell(1,12) in which each element of resultcell is a 3D array. something like following.
for numbercol = 1:size(X,2)
summation = 0; % Reset summation value to 0 for next element
for numbermats = 1:size(X,1) % Loop through all matrices in first
column
summation = summation + X{numbermats,numbercol}; % Add next
matrix element
end % Numbermats for
resultcell{1,numbercol} = summation/numbermats; % save avarage of each column of the cell X in the cell resultcell
end;
Bob Thompson
Bob Thompson am 15 Mär. 2018
Cool, glad I could help. I deliberately avoided putting the answer into a cell matrix since I figured it would just be numbers and a cell matrix of numbers is just extra complicated, but you do what you need to.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 15 Mär. 2018
A - your cell array
one variant
[m,n,k] = size(A{1});
[h,l] = size(A);
A1 = reshape(cat(3,A{:}),m,n,k,h,l);
out = squeeze(num2cell(mean(A1,4),1:3))';

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by