what difference does it make if we use rand and randn

4 vues (au cours des 30 derniers jours)
will99
will99 le 9 Oct 2015
Commenté : Mike Garrity le 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

Réponses (2)

Walter Roberson
Walter Roberson le 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 commentaire
Mike Garrity
Mike Garrity le 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))

Connectez-vous pour commenter.


Thorsten
Thorsten le 9 Oct 2015
Modifié(e) : Thorsten le 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.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by