Sum through an array until a value is reached, then continue

조회 수: 3 (최근 30일)
Anthony
Anthony 2018년 11월 2일
댓글: Anthony 2018년 11월 2일
Assume you have 2 arrays x = linspace(0.001,0.005,1000); y = linspace(0,1,1000);
I want to start at the beginning of x, and sum consecutive columns until the sum = 0.1, then take the average of y across that range.... then continue doing this until the end of x
  댓글 수: 6
Bruno Luong
Bruno Luong 2018년 11월 2일
편집: Bruno Luong 2018년 11월 2일
"With the values given, the first 100 columns would sum to 0.1"
No body know where the 100 comes from. Anyone is guessing and people just wastes theirs times for you.
Not give example is better than give one that doesn't make sense.
Anthony
Anthony 2018년 11월 2일
Thanks for trying Bruno, you're a peach!

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

채택된 답변

Matt J
Matt J 2018년 11월 2일
편집: Matt J 2018년 11월 2일
c=cumsum(x);
G=discretize(c, 0:0.1:c(end));
result = splitapply(@mean, y, G),

추가 답변 (2개)

madhan ravi
madhan ravi 2018년 11월 2일
편집: madhan ravi 2018년 11월 2일
mean(y(cumsum(x)<=0.1))
  댓글 수: 8
Bruno Luong
Bruno Luong 2018년 11월 2일
Yes 1 over 4 people figures it out ...by chance.
Anthony
Anthony 2018년 11월 2일
Thanks again Bruno, you're the best!

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


Guillaume
Guillaume 2018년 11월 2일
sumx = cumsum(x);
meanybelowthreshold = mean(y(sumx <= 0.1));
meanyabovethreshold = mean(y(sumx > 0.1));

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by