How to loop unifrnd(a,b) with a and b outputs of the linspace function
9 views (last 30 days)
Show older comments
Hello,
I am attempting to create a function that makes use of iterative techniques to uniformly sample from a series of discrete distributions that are partially obtained using the linspace function. I will include an example that follows this which I hope will help elucidate my question.
linspace(0,100,51) = [0,2,4,6,8...]
x1 = unifrnd(0+0.01, 2-0.01)
x2 = unifrnd(2+0.01, 4-0.01)
x3 = unifrnd(4+0.01, 6-0.01)
x4 = unifrnd(6+0.01, 8-0.01)
...
2 Comments
Rik
on 8 Oct 2022
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
Answers (1)
Walter Roberson
on 16 Sep 2022
x = linspace(0,100,51);
output = arrayfun(@unifrnd, x(1:end-1), x(2:end));
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!