问题
(1) I have two column vectors.
Eg. x = [283167.778
*289387.207
289705.322]
y = [9121643.314
9098348.666*
9099832.621]
(2) I'd like to make a weighted random sampling using these vectors: when I'll select the element 289387.207 in vector x, necessarily I'll choose the element 9098348.666 in vector y.
(3) Also, I have the weighted w vector for each element in vector x and y.
How can I implement this in MatLab? Thanks!
回答1:
For random selection:
sel_idx= randi(3);
outputx = x(sel_idx);
outputy = y(sel_idx);
for random weighing:
w = rand(size(x));
w = w./sum(w); % normalize
outputx = w(:)'*x(:);
outputy = w(:)'*y(:);
来源:https://stackoverflow.com/questions/16549174/weighted-sampling-with-2-vectors