how to generate floating points randomly????
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
David Young
2011-6-2
matrix_rand = rand(rowsize, colsize);
5 个评论
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.
更多回答(1 个)
Walter Roberson
2011-6-2
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!