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

1 回表示 (過去 30 日間)
Mohammed Yousuf
Mohammed Yousuf 2017 年 11 月 9 日
編集済み: Stephen23 2017 年 11 月 9 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by