Alternative to "round" for accurate accumulation
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a vector
A=[0.970, 0.486, 0.439, 0.0143, 0] % Ref vector from Algorithm-1
B=7 % Final sum expected from A
A1=A/sum(A) % Proportionate for sum==1
B1=round(A1*B)
B1=[4 2 2 0 0] %Sum is 8 (not 7)
The objective is to convert vector A into integer such that the sum is B=7. Is there any matlab function by which sum of 7 can be achieved. Or can you please suggest other way. Kindly note that A changes in every iteration.
댓글 수: 2
madhan ravi
2018년 8월 28일
Can you elaborate what you are trying to do and what you are trying to achieve?
채택된 답변
Stephen23
2018년 8월 28일
>> n = fzero(@(k)sum(round(A*k))-7,[0.01,100])
n = 3.4811
>> V = round(A*n)
V =
3 2 2 0 0
>> sum(V)
ans = 7
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!