Hello, How can I generate a uniformly distributed random vector with its sum to be equal to 1?
Prashant Kumar answered .
2025-11-20
xy = rand(100,2); plot(xy(:,1),xy(:,2),'.')
Now, lets do the sum projection that virtually everyone poses. (Yes, it is the obvious choice. Now we will see why it is the wrong approach.)
xys = bsxfun(@rdivide,xy,sum(xy,2)); hold on plot(xys(:,1),xys(:,2),'ro') axis equal axis square

figure xyr = randfixedsum(2,100,1,0,1)'; plot(xyr(:,1),xyr(:,2),'ro') axis equal axis square
