필터 지우기
필터 지우기

Sum up parts of a vector?

조회 수: 3 (최근 30일)
Thor
Thor 2013년 1월 24일
Dear all,
I have a 105120*1 vector and I want to sum up in steps of 288. So I want to have the sum of the first 288 elements, then the sum of the next 288 elements and so, until the end of the vector. So finally I want to have a new vector of the dimension 365*1. So I need finally 365 sums. How can I do that?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 24일
편집: Azzi Abdelmalek 2013년 1월 24일
x=rand(105120,1);
out=sum(reshape(x,288,[]))'
  댓글 수: 1
Thor
Thor 2013년 1월 24일
Great! Thank you!

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

추가 답변 (1개)

Wayne King
Wayne King 2013년 1월 24일
편집: Wayne King 2013년 1월 24일
Something like
k = 1;
stepsize = 288;
for nn = 1:288:105210-stepsize
partsum(k) = sum(vekt(nn:nn+stepsize-1));
k = k+1;
end
That's one possible way. There are many others.
  댓글 수: 1
Thor
Thor 2013년 1월 24일
Great too! Thank you!

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by