Taking an average of every n elements of one column

4 Ansichten (letzte 30 Tage)
Tony Chan
Tony Chan am 8 Mai 2020
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!

Antworten (1)

David Goodmanson
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.

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!

Translated by