how to take the average of a matrix of any size
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How do I compute the mean of all the values in a matrix of any size
0 commentaires
Réponses (2)
Wayne King
le 14 Mar 2012
mean()
X = randn(100,100);
mean(mean(X))
or
mean(X(:))
4 commentaires
Wayne King
le 14 Mar 2012
If you want the means of the columns or the rows, you can use mean() with the dimension argument
X = mean(X,1);
or
X = mean(X,2);
Sean de Wolski
le 14 Mar 2012
mean(X(:))
or for speed:
N = numel(X);
sum(reshape(X,N,1))/N;
or for fun:
eval([repmat('mean(',1,ndims(X)) 'X' repmat(')',1,ndims(X)) ';']);
1 commentaire
Jan
le 15 Mar 2012
A strange definition of "fun".
I think, that "sum(X(:))/numel(X)" is more fun, it is even _nice_.
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!