function [xout]=resampLV(x,w)
%  Note:  This just works on indicies. #states doesn't matter when picking
%  particles.
%
% Prob Rob p.111.

nparticles=max(size(x));

xout=0*x;
r=(1/nparticles -0).*rand(1,1)+0;
c=w(1);
i=1;
for m=1:nparticles;
    U=r+(m-1)*(1/nparticles);
    while U>c,
        i=i+1;
        c=c+w(i);
    end
    xout(m,:)=x(i,:);
end
