what difference does it make if we use rand and randn

4 ビュー (過去 30 日間)
will99
will99 2015 年 10 月 9 日
コメント済み: Mike Garrity 2015 年 10 月 9 日
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

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 9 日
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 件のコメント
Mike Garrity
Mike Garrity 2015 年 10 月 9 日
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))

サインインしてコメントする。


Thorsten
Thorsten 2015 年 10 月 9 日
編集済み: Thorsten 2015 年 10 月 9 日
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.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by