Thursday 8 December 2011

Matlab Random Number Generation Example | Random Number Generate between two Numbers in Matlab

Matlab random number generation using rand() function.This function generate random number with floating points. if you want int number means,you round function used to round the values.Random number only generate between 0 to 1.Random number generate as following command.

>>rand
ans =

0.6557

Matlab generate random number with some vector size.If you want random number generate 5 row with 3 then use following command,

>> rand(5,3)

ans =

0.3816 0.4456 0.6797
0.7655 0.6463 0.6551
0.7952 0.7094 0.1626
0.1869 0.7547 0.1190
0.4898 0.2760 0.4984

Matlab random number generate between two int point means use following command

>> startpnt = 10;
>> endpnt = 20;
>> startpnt+(endpnt-startpnt)*rand(5,2)

ans =

12.5108 15.8526
16.1604 15.4972
14.7329 19.1719
13.5166 12.8584
18.3083 17.5720

Here generate random rumber between 10 to 20 values.If you want real number means you have used to round function.round(startpnt+(endpnt-startpnt)*rand(5,2)) get real numbers between 10 to 20.

Kindly Bookmark and Share it:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...