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?

 채택된 답변

Birdman
Birdman 2018년 2월 21일

1 개 추천

Use randfixedsum.m function from the following link:
and write
randfixedsum(5,1,1,0,1)

댓글 수: 4

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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by