Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
how to extract numbers from array whose sum is constant number?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
You need to round to some degree, either when generating the A array, or when testing the sum.
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개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!