Taking an average of every n elements of one column
조회 수: 4 (최근 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!