Taking average of 3 rows from a matrix
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hyunjae Jeon
am 20 Mär. 2019
Kommentiert: Hyunjae Jeon
am 20 Mär. 2019
I have a data that has 10 columns and 369 rows.
I would like to get average of every 3 rows so that the output will be 10 columns 123 rows.
So that I will be getting average of first three rows in the first row in the output spreadsheet.
Thank you in advance.
1 Kommentar
Akzeptierte Antwort
madhan ravi
am 20 Mär. 2019
Simpler and faster than the other two:
[m,n]=size(A); % A is your matrix
Mean=reshape(mean(reshape(A,3,[])),[],n)
Weitere Antworten (2)
KSSV
am 20 Mär. 2019
A = rand(369,10) ;
idx = repmat(3,1,369/3) ;
% arrange data
B = mat2cell(A,idx) ;
% get mean
M = cellfun(@mean,B,'un',0) ;
M = cell2mat(M)
madhan ravi
am 20 Mär. 2019
Using mat2cell() and cellfun() is slower than an explicit loop follow this instead:
[m,n]=size(A); % A is your matrix
U1=reshape(A.',n,3,m/3);
Uu=mean(permute(U1,[2 1 3]));
Mean=squeeze(Uu).';
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!