Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to extract numbers from array whose sum is constant number?

1 回表示 (過去 30 日間)
BHUKYA VENKATESH
BHUKYA VENKATESH 2022 年 9 月 9 日
閉鎖済み: Rik 2022 年 9 月 9 日
I have a randum number array size is (100,1) and i want have 10 elements from this array and their sum should be a constant number.
A=rand(100,1)
B=A(i, j, k,.....)
C=sum(B)==10
  3 件のコメント
Rik
Rik 2022 年 9 月 9 日
Also, this is never going to work exactly. The rand function returns values between 0 and 1 with double precision. The odds of the sum of 10 values being one specific value are astronomical.
Did you perhaps mean this?
A=randi([0 1],[1,100]) % row vector for more compact display
A = 1×100
1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 1 1
You need to round to some degree, either when generating the A array, or when testing the sum.
Rik
Rik 2022 年 9 月 9 日
Instead of posting a new question, you could also have responded in a comment here.
Since this question is now either moot or a duplicate, I will close it.

回答 (0 件)

この質問は閉じられています。

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by