필터 지우기
필터 지우기

Generate a random vector elements that sum up to one ?

조회 수: 3 (최근 30일)
Rahim Rahim
Rahim Rahim 2022년 12월 29일
답변: Image Analyst 2022년 12월 29일
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.

답변 (1개)

Image Analyst
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.
V = 1×6
0.1426 0.2113 0.2330 0.0874 0.2157 0.1100
theSum = sum(V)
theSum = 1
but many people use this:
which is supposedly better for some reason.

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by