How to round numbers using the decimals as a probability?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aron
am 13 Apr. 2023
Kommentiert: Walter Roberson
am 13 Apr. 2023
Hi, I am trying to create code where the decimals are used as probability of how the value is rounded. For example, I have array of the following values: [ 1.04 ; 0.96 ; 0.22 ; 1.56 ] and for the first element there is a 4% chance the value gets rounded up to 2 and a 96% chance it gets rounded to 1. For the second element there is a 96% probability that it gets rounded up to 1 and a 4% it gets rounded to 0.
1 Kommentar
Walter Roberson
am 13 Apr. 2023
What is the rule? Round down 96% of the time for values with even row numbers, and round down 96% of the time for values with odd row numbers? If so then should that be modified if there are multiple columns ?
Akzeptierte Antwort
David Hill
am 13 Apr. 2023
A=10*rand(1,10)
B=floor(A)+((A-floor(A))>rand(1,10))
3 Kommentare
Walter Roberson
am 13 Apr. 2023
No, each entry in A should be rounded individually.
B=floor(A)+((A-floor(A))>rand(size(A)))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!