I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100
0 commentaires
Réponses (2)
KSSV
le 9 Nov 2017
A = rand(100) ;
m = 10 ; n = 100 ;
l = size (A) ./ [m n];
T = mat2cell (A, repmat (m, l(1), 1), repmat (n, l (2), 1));
M = cellfun(@mean,T,'un',0) ;
M = cell2mat(M) ;
0 commentaires
Stephen23
le 9 Nov 2017
Modifié(e) : Stephen23
le 9 Nov 2017
This is actually really simple with reshape. Here is an example with a 6x4 matrix where I average every 3 rows to give a 2x4 matrix:
>> M = randi(9,6,4)
M =
8 6 8 4
3 7 9 8
5 2 5 6
8 2 8 6
2 3 2 3
4 3 4 7
>> N = 3; % number of rows to average over
>> R = size(M,1)/N % final number of rows: must be integer!
R = 2
>> reshape(mean(reshape(M,N,[]),1),R,[])
ans =
5.3333 5.0000 7.3333 6.0000
4.6667 2.6667 4.6667 5.3333
And checking the first value by hand:
>> mean([8,3,5])
ans = 5.3333
0 commentaires
Voir également
Catégories
En savoir plus sur Numeric Types 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!