Taking an average of every n elements of one column
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I have a 144x73x551 array. I want to take the average of every 12 elements in the third column into a new array. What is the best way to go about it? Thanks!
0 Kommentare
Antworten (1)
David Goodmanson
am 8 Mai 2020
Bearbeitet: David Goodmanson
am 8 Mai 2020
Hi Tony,
a = rand(144,73,551);
b = squeeze(a(:,3,:)); % take all the third columns
c = mean(reshape(b,12,[])); % reshape them into 12-row columns, take the mean
d = reshape(c,144/12,[]); % put the 12 means down each new column, 551 columns
Taking every third column reduces the 3d array to a 2d array. The result is a set of means down each new column, with the old index down the third dimension being the column index of the new array.
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!