what difference does it make if we use rand and randn

4 views (last 30 days)
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

Answers (2)

Walter Roberson
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
Mike Garrity
Mike Garrity on 9 Oct 2015
Another visualization which I think does a good job of showing the difference between the distributions of the two functions is this:
scatter(rand(1,1000),rand(1,1000))
versus this:
scatter(randn(1,1000),randn(1,1000))

Sign in to comment.


Thorsten
Thorsten on 9 Oct 2015
Edited: 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.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!