hi, i would like to generate a column vector using rand function e.g rand(5,1), so that none of the element is bigger than 1 and less than 0. and i want the sum of all the elements to equal 1 exactly. how do i do it?

 Akzeptierte Antwort

Birdman
Birdman am 21 Feb. 2018
Use randfixedsum.m function from the following link:
and write
randfixedsum(5,1,1,0,1)

4 Kommentare

but it is giving me a warning: Function power has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.
and if i write a code like this-
x=randfixedsum(5,1,1,0,1)
then an error message is shown: Output argument "x" (and maybe others) not assigned during call to "randfixedsum".
Randfixedsum has no function defined named power, nor, knowing Roger, would he ever have done that.
Are you sure that you did not define a function named power yourself? Try this:
which power -all
That would indeed cause a major problem in MATLAB, had you done that.
thnx, got the solution.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by