How to get only random samples which are in allowed range and reject the rest?
5 views (last 30 days)
Show older comments
Hi!
u = rand(3,1)-0.5;
y = - 10 * sign(u).* log(1- 2* abs(u));
The output y is a 3*1 column vector (of samples drawn from Laplacian Distribution).I need to reject those y values which are outside the allowed range say [-15,15](To get samples from Truncated Laplace Distribution) and only accept the in-range values.If I don't get all 3 in-range values in the first iteration,i have to go for second iteration and so on until i get 3 in-range values.
Can you please help me out with the matlab script? It would be also helpful if someone can suggest any other alternative method of drawing i.i.d samples from Truncated Laplace Distribution.
Thanks
0 Comments
Accepted Answer
KSSV
on 10 May 2022
idx = [0 0 0] ;
while nnz(idx)~=3
u = rand(3,1)-0.5;
y = - 10 * sign(u).* log(1- 2* abs(u));
idx = y >=-15 & y <= 15 ;
end
y
0 Comments
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!