how to generate floating points randomly????

Hello! i am new in matlab and need help, as em writing code for generating matrix of size 20-by-4. rowsize=20, colsize=4 and need to generate between [0 1], suppose i want matrix having random values like [0.25 0.5 0.05 0.20] and so on.... but when i run my code then it returns me 20-by-4 matrix of 0's and 1's.....which function i should use to get required results...please help and thanks in advance..
{ matrix_rand=randint(rowsize, colsize, [0 1]); it returns
1 0 0 0
1 1 1 0
1 1 0 1
0 0 0 0
0 1 0 0
1 1 1 1
0 1 0 0
1 1 0 0
1 1 1 0
0 0 0 1
1 1 0 1
1 0 1 1
1 0 0 1
1 0 0 0
1 1 1 0
0 1 0 1
1 0 0 1
0 0 0 1
1 1 0 0
but when i write rand(), then it returns nothing

 채택된 답변

David Young
David Young 2011년 6월 2일

0 개 추천

matrix_rand = rand(rowsize, colsize);

댓글 수: 5

Talat
Talat 2011년 6월 2일
Sory, i should elaborate my problem clearly.... i also want that sum of each row should be "1" suppose[0.25 0.5 0.05 0.20], if add these values then i get '1'... plz help me how should i give the limits also.....
Talat
Talat 2011년 6월 2일
hello David, plz help me to resolve problem..... thanx
David Young
David Young 2011년 6월 8일
You can make the sum of each row add to 1 like this:
matrix_rand_normalised = bsxfun(@rdivide, matrix_rand, sum(matrix_rand,2))
Walter Roberson
Walter Roberson 2011년 6월 8일
Please do *not* use the normalization method! It leads to bias in the generated numbers! Use Roger Stafford's method instead.
Talat
Talat 2011년 6월 10일
Yes! I have done my work with Roger Stafford's method ... and got results...Thanx both of you guys for suggestions....

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 6월 2일

0 개 추천

Roger Stafford has a MATLAB File Exchange contribution for generating random numbers with a fixed sum. See http://www.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum

댓글 수: 1

Talat
Talat 2011년 6월 2일
Thanks sooooo much... i got it... it will help me for sure

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

카테고리

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

질문:

2011년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by