Alternative to "round" for accurate accumulation

1 回表示 (過去 30 日間)
Mukund
Mukund 2018 年 8 月 28 日
回答済み: Stephen23 2018 年 8 月 28 日
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
madhan ravi 2018 年 8 月 28 日
Can you elaborate? which has to be eight A1 or B or B1?
madhan ravi
madhan ravi 2018 年 8 月 28 日
Can you elaborate what you are trying to do and what you are trying to achieve?

サインインしてコメントする。

採用された回答

Stephen23
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by