Sum the component of a vector till a certain value
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi,
given the vector G= [2 4 4 5 6 16 8 9 21 3 5 8 12 34 5 6 8] I want to obtain a new vector S with the same component but cutted at the element X when the sum of each single elements exceed a specific value Y.
So if in our case Y=80. the new vector S would be
S = [2 4 4 5 6 16 8 9 21 3], in this case the sum of the elements reach 78.
Adding the element 5 we obtain 83, exceeding our limit. That's why we cut at the element X=3, obtaining S= [2 4 4 5 6 16 8 9 21 3].
Does someone know hot to implement this?
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 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!