Edivaldo
Edivaldo

Reputation: 1

Weighted sampling with 2 vectors

(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!

Upvotes: 0

Views: 200

Answers (1)

Gunther Struyf
Gunther Struyf

Reputation: 11168

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(:);

Upvotes: 1

Related Questions