MATLAB Answers


what difference does it make if we use rand and randn

Asked by will99
on 9 Oct 2015
Latest activity Commented on by Mike Garrity
on 9 Oct 2015
I feel like these are basics things I need to understand before getting more into matlab 1.using matlab I used rand to generate sample data and then do the graph using hist .. but then I changed rand to randn and the only difference is using randn make the graph look narrow ... what is the different between rand and randn
2.also when plotting graph what difference does it make if we plot the random sample data or if we plot the data mean of the random sample data.. all I can tell is both graph look different but I don't know how it will help if we find the mean
3.what is the different between 1xn and nxn matrix and how using 1xn or nxn matrix will affect the graph
thank you.. sorry of my questions are not clear I tried to make it as simple as I can


Sign in to comment.


2 Answers

Answer by Walter Roberson
on 9 Oct 2015

plot(randn(1,100)) and take a closer look at the y axis. It probably goes from about -3 to +3. Now do the same thing with 1000 instead of 100: you will probably reach +4 to -4 . If you were to plot further to 100000 you will probably start getting -5 to +5 as you get more and more occurrences of the rare events.
Now try the same thing with rand instead of randn.

  1 Comment

Another visualization which I think does a good job of showing the difference between the distributions of the two functions is this:
versus this:

Sign in to comment.

Answer by Thorsten
on 9 Oct 2015
Edited by Thorsten
on 9 Oct 2015

1. Basically rand generates uniformly distributed data and randn normally distributed data. For more, have a look at
help rand
help randn
2. The mean is the mean of the data. It can help you do compare different data sets and have a look if the means are different.
3. 1xn is just a single row with n columns, so you will get a single line in the plot. nxn is a matrix with n rows and n columns, and plotting this will yield n different lines, one for each column.


Sign in to comment.