for loop help and counts
2 views (last 30 days)
Show older comments
I have an array and started coding but I've come stuck:
CDF=[-4 0
-3 0.1
-1 0.4
1 0.6
3 0.9
4 1.0];
xi = interp1(CDF(:,2), CDF(:,1), [0.05; 0.15; 0.63])
for i=1:10000
y=rand(1);
xi_y = interp1(CDF(:,2), CDF(:,1), y)
I need to run a for loop 10000 times to generate a random number y between 0-1. I need to calculate the corrosponding x value from the array and run a count function into 100 equally sized bins between x=-4 and x=4
1 Comment
Image Analyst
on 1 Apr 2014
Felix's original question, so it will be here after he deletes it.
I have an array and started coding but I've come stuck:
CDF=[-4 0
-3 0.1
-1 0.4
1 0.6
3 0.9
4 1.0];
xi = interp1(CDF(:,2), CDF(:,1), [0.05; 0.15; 0.63])
for i=1:10000
y=rand(1);
xi_y = interp1(CDF(:,2), CDF(:,1), y)
I need to run a for loop 10000 times to generate a random number y between 0-1. I need to calculate the corrosponding x value from the array and run a count function into 100 equally sized bins between x=-4 and x=4
Answers (1)
Image Analyst
on 1 Apr 2014
Just index it, xi_y(i), so you save all the x values, and then when the loop finishes pass xi_y into hist() or histc().
2 Comments
Image Analyst
on 1 Apr 2014
You have a history of deleting your questions so I'm just going to suggest this: http://www.mathworks.com/matlabcentral/answers/8026-best-way-s-to-master-matlab Good luck.
See Also
Categories
Find more on Line Plots 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!