Finding an average matrix from each matrix in an array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Roisin Coveney
el 13 de Jul. de 2021
Comentada: Roisin Coveney
el 14 de Jul. de 2021
I have an array of matrices, each with the same dimensions, I am looking to get one matrix which has the average value of all the matrices at each point, any advice on how to do this?
1 comentario
Joseph Cheng
el 13 de Jul. de 2021
i think the matlab coding help would depend on how you've arranged your array of matrices. but over all if you have matrix of N dimensions and you want the index average across the different matrices; the simplest would be to just add all these together to a single N dimensioned matrix and divide that by total number of matrices.
Respuesta aceptada
Image Analyst
el 13 de Jul. de 2021
averageMatrix = (matrix1 + matrix2 + matrix3) / 3;
4 comentarios
Más respuestas (1)
Jan
el 13 de Jul. de 2021
Editada: Jan
el 13 de Jul. de 2021
Which kind of array contains the matrices? A cell array, a numerical 3D array, a struct array? The solution depends on this detail.
A = {rand(4), rand(4), rand(4)}; % Cell array
meanA = sum(cat(3, A{:}), 3);
B = rand(3, 4, 4); % 3 4x4 matrices in numerical 3D array
meanB = reshape(sum(B, 1), 4, 4);
C(1).data = rand(4); % Struct array
C(2).data = rand(4);
C(3).data = rand(4);
meanC = sum(cat(3, C.data), 3)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!