Reputation: 2087
I am looking for a quick way to construct a vector of size n.
The sum of all its elements must be 1.
For example if n = 5 the vector should be v = [0.1 0.3 0.03 0.07 0.5].
Any ideas on how to do that?
Upvotes: 0
Views: 305
Reputation: 7132
One simple possibility is
v=rand(5,1); v=v/sum(v)
Upvotes: 4
Reputation: 5251
Just create the vector and normalise it:
v = v ./ sum(v);