randn() function command help
2 views (last 30 days)
Show older comments
I am currently trying to learn MATLAB independently and had a question about a command that used randn().
nddata = fix(8*randn(10,5,3))
I understand what the fix() function does, and the multidimension array that is created by randn. However, I am not sure what 8 is doing here, it is not multiplying the outcome of the random numbers and it is not part of the limit. So I just want to know the purpose of the 8 here.
Thanks
0 Comments
Answers (1)
dpb
on 10 Jul 2020
nddata = fix(8*randn(10,5,3))
"... I am not sure what 8 is doing here, it is not multiplying the outcome of the random numbers ..."
What makes you think that???
Of course it is.
That's the purpose; the originator of the code wanted that scaling on a RNVariate sample. Why would want to fix() the result is perhaps the more interesting Q? but undoubtedly had something to do with the particulars of the simulation model.
2 Comments
John D'Errico
on 10 Jul 2020
Exactly the one thing we DO know about that line is it is indeed mutiplying by 8. Fix, as applied to normally distributed numbers is a bit more interesting, but taken out of context, it is impossible to know why the fix is in there. Only the person who wrote the line.
randn produces Gaussian random numbers, with mean 0 and a population standard deviation = 1. Therefore, if you multiply by 8, the sample now has still mean zero, but the population standard deviation is 8.
The fix just produces something strange. :)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!