I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100

6 visualizaciones (últimos 30 días)
I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100

Respuestas (2)

KSSV
KSSV el 9 de Nov. de 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) ;

Stephen23
Stephen23 el 9 de Nov. de 2017
Editada: Stephen23 el 9 de Nov. de 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

Categorías

Más información sobre Numeric Types 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!

Translated by