Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between unifrnd and rand() functions in matlab

Tags:

random

matlab

I am a little bit confuse about use of rand() and unifrnd() in interval [0,1]. How are both different? Definitions of these from Matlab tutorial are as follows:

rand() - Uniformly distributed pseudorandom numbers 
unifrnd() - Continuous uniform random numbers  
like image 877
user2771151 Avatar asked Sep 04 '14 08:09

user2771151


People also ask

How to generate a uniform distribution in MATLAB?

r = unifrnd( a , b , sz ) generates an array of uniform random numbers, where the size vector sz specifies size(r) .

How do you change the Rand interval in Matlab?

By default, rand returns normalized values (between 0 and 1) that are drawn from a uniform distribution. To change the range of the distribution to a new range, (a, b), multiply each value by the width of the new range, (b – a) and then shift every value by a.


1 Answers

I assume you mean unifrnd, (not "unifrand").

unifrnd is part of the Statistics Toolbox, whereas rand is a Matlab basic function.

unifrand is just a wrapper of rand that lets you specify additional parameters to define the interval of the random values (rand outputs values in [0,1]). You could do the same with rand using (a-b)*rand(...)+b, where a and b is the desired interval. Type open unifrnd in Matlab to see unifrnd's code.

Another difference is that, in recent Matlab versions, rand lets you specify the data type of the generated output: single or double.

like image 103
Luis Mendo Avatar answered Oct 10 '22 02:10

Luis Mendo