Sum every nth row or array

조회 수: 32 (최근 30일)
Terence Ryan
Terence Ryan 2012년 1월 30일
답변: Aubai 2017년 1월 20일
Hello all,
I have an array which is 150x8192 elements. I want to sum every 4th row of this array, making the new array (150/4)x8192. I am running into issue determining the correct code. I have tried some simple nested for loops, but I always seem to get a new array with the same dimensions (150x8192). Thanks for any suggestions!

답변 (2개)

Andreas Goser
Andreas Goser 2012년 1월 30일
If this is your matrix
A=rand(150,8192);
Then this is "every 4th row"
A(1:4:end,:);
I am not 100% sure what you meand about "sum every 4th row" and still you have the same number of columns, but something like
sum(A(1:4:end,:),1)
may be what you need.

Aubai
Aubai 2017년 1월 20일

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by