Hi,
I have some code like this:
for k = 1:p new_index = randsample([1:n,nan],1,true,tot_weights(k,:)); curr_indexes(k) = new_index; if ~isnan(new_index) currx(k) = x(i,new_index); curry(k) = y(i,new_index); else currx(k) = nan; curry(k) = nan; endend
where tot_weights is a p x n matrix that has the weights for the sampling. I am trying to get rid of the for loop and vectorize the function. Basically I just want to get a total of p values that are between 1 to n or nan. The probability for the kth value to be a certain value is given by the weights in the kth row of tot_weights.
Any suggestions would be greatly appreciated! Right now, this for loop takes an annoying amount of time to run.
Cheers,
Sam
Best Answer