Generate a random vector elements that sum up to one ?
3 次查看(过去 30 天)
显示 更早的评论
Let us consider that we have a vector V.
Where V(1,6): the vector contains 6 columns (cases).
How can I set up a random vector that will sum up to 1. I mean that: sum(V(1,:)) == 1 ).
where all the elements should be beweent 0 and 1. Upperbounder =1 and lowbounder =1.
0 个评论
回答(1 个)
Image Analyst
2022-12-29
Try this:
V = rand(1, 6);
V = V / sum(V) % Make it sum to 1 by dividing by the sum.
theSum = sum(V)
but many people use this:
which is supposedly better for some reason.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!