Matlab newbie - sampling with replacement

1 view (last 30 days)
fraz
fraz on 4 Aug 2014
Commented: fraz on 4 Aug 2014
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
Image Analyst on 4 Aug 2014
That's not MATLAB code. Maybe you should be asking in a different forum.
fraz
fraz on 4 Aug 2014
Oh.. That was meant to be a pseudocode.. and I am trying to replicate it in matlab

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!