Matlab newbie - sampling with replacement
1 view (last 30 days)
Show older comments
Hi,
I have a probability array 'probs'. probs(i) is the probability I will select an ith row in the matrix A. How do I simulate this?
I want to select at least 'k' rows from this matrix. What I was thinking was something like:
rows_select = zeros(1,k)
rows_select_index = 0
probs_index = 0
while true:
prob_i = probs(probs_index)
flip_coin = Bernouli(prob_i)
if flip_coin == 1, ( row_select(rows_select_index) = probs_index; rows_select_index++;)
probs_index ++;
if (probs_index == k) break
Does that make any sense?
2 Comments
Image Analyst
on 4 Aug 2014
That's not MATLAB code. Maybe you should be asking in a different forum.
Answers (0)
See Also
Categories
Find more on Logical 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!