Sum through an array until a value is reached, then continue
이전 댓글 표시
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
madhan ravi
2018년 11월 2일
give a short example of your desired result
Bruno Luong
2018년 11월 2일
Description inaccurate and contradictory.
It looks like the "cumulative sum" is actually y (100 elements).
x never reaches 0.1.
Cumulative sum on x and y never give 0.1 crossing at 100 elements.
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
2018년 11월 2일
채택된 답변
추가 답변 (2개)
madhan ravi
2018년 11월 2일
편집: madhan ravi
2018년 11월 2일
mean(y(cumsum(x)<=0.1))
댓글 수: 8
Anthony
2018년 11월 2일
madhan ravi
2018년 11월 2일
see the edited answer
Anthony
2018년 11월 2일
madhan ravi
2018년 11월 2일
did you read Brunos comment?
Guillaume
2018년 11월 2일
In case you haven't noticed you were given another answer that matches your description.
"this deosn't produce a correct output" is totally useless if you don't tell us what the correct output is. Vagues descriptions that don't actually match the example you've given doesn't cut it.
As has been pointed out, your statement "the first 100 columns would sum to 0.1" is incorrect. cumsum(x) reaches 0.1 at column 86.
Anthony
2018년 11월 2일
Bruno Luong
2018년 11월 2일
Yes 1 over 4 people figures it out ...by chance.
Anthony
2018년 11월 2일
Guillaume
2018년 11월 2일
sumx = cumsum(x);
meanybelowthreshold = mean(y(sumx <= 0.1));
meanyabovethreshold = mean(y(sumx > 0.1));
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!