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

조회 수: 1 (최근 30일)
I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100

답변 (2개)

KSSV
KSSV 2017년 11월 9일
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 2017년 11월 9일
편집: Stephen23 2017년 11월 9일
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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by