Taking an average of every n elements of one column
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
David Goodmanson
2020-5-8
编辑:David Goodmanson
2020-5-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!