Efficient allocation of random numbers(U(0,1)) into categories
조회 수: 4(최근 30일)
표시 이전 댓글
I am trying to create a function which takes two arguments as input, one a vector of values drawn from a uniform distribution and the other input a number of values between 0 ad 1. It should then index the values from the first input with a number corresponding to its category in the second input.
For example Input1 = [0.2 0.5 0.90 0.995] input2 = [0 0.81 0.99 1] Output = [0 0 1 2]
At present i am using a double for loop with an if statement
for i=1:length(randoms)
for r = 1:(length(ShockProbabilities)-1)
if randoms(i) >= (ShockProbabilities(r)) && randoms(i) < (ShockProbabilities(r+1)); randoms(i)=(r-1); end
end
end
Could any one suggest how i might speed this up ? i am sure there is a way and i dont like using 2 for loops and an if statement. I am just curious, i dont really need it as such
Thanks :)
댓글 수: 0
채택된 답변
추가 답변(0개)
참고 항목
범주
Find more on Monte Carlo Analysis in Help Center and File Exchange
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!