summing columns based on certain interval

조회 수: 4 (최근 30일)
umberto kober
umberto kober 2021년 5월 24일
댓글: umberto kober 2021년 5월 24일
hi
I need your help with summing columns based on certain interval
I could not find a solution already discussed. I have a matrix of size 153×10
I need to split the sum in 3 parts
the first part is the first 51 lines
the second is from line 53 to 102
the third sum is from line 104 to 153
thank you in advance

채택된 답변

the cyclist
the cyclist 2021년 5월 24일
The best answer will depend on what specifically you want the output to be, and also how generalizable the solution needs to be. So, for example ...
% Create some pretend input
rng default
M = rand(153,10);
% The output
sumM(1,:) = sum(M(1:51,:));
sumM(2,:) = sum(M(53:102,:));
sumM(3,:) = sum(M(104:153,:));
disp(sumM)
28.5815 25.2191 26.3169 25.5789 25.1921 25.3849 24.9313 27.1576 26.0622 29.7548 24.4947 23.2450 23.5665 23.9650 24.6723 22.3731 27.5794 27.1525 31.6407 22.7831 22.6260 25.3312 25.3853 28.5369 20.4879 19.9393 25.2790 24.8022 23.1605 20.5209
This does what you ask. But I expect it is not everything you want. But maybe? Give us more details.

추가 답변 (1개)

Torsten
Torsten 2021년 5월 24일
sum(sum(A(1:51,:)))
sum(sum(A(53:102,:)))
sum(sum(A(104:153,:)))
  댓글 수: 3
the cyclist
the cyclist 2021년 5월 24일
FYI, in R2018b or later, one could instead do
sum(A(1:51,:),'all')
and so on, rather than applying the sum() twice.
umberto kober
umberto kober 2021년 5월 24일
thank you!!!

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by