Write a matlab code to generate a 1 X N matrix with values in the range of 1-100 according to a normal distribution with mean= 0 and variance=1
51 views (last 30 days)
Show older comments
Can anyone help me with this please
1 Comment
the cyclist
on 18 Sep 2021
The question is confusing to me, especially where you say "in the range of 1-100".
If you mean that the values should be from 1-100, then how can the mean value be equal to 0?
Or do you mean that the matrix should be length N, but only elements 1-100 should be filled in? If so, then @Ravi Narasimhan's idea of using randn to fill in the first 100 elements should be straightforward.
Answers (2)
Ravi Narasimhan
on 18 Sep 2021
The documentation for the randn function may be of interest.
0 Comments
Walter Roberson
on 18 Sep 2021
Edited: Walter Roberson
on 18 Sep 2021
You can create a normal distribution and then truncate it. The truncated distribution still has total probability 1, which is handled by multiplying the probability density function by enough that its integral totals 1.The modified probability density function no longer has 0 mean and 1 standard deviation, though.
You can see from the distribution that even though values from 1 to 100 are permitted, that statistically there is very little beyind 3.5
D = makedist('normal', 0, 1);
Td = truncate(D, 1, 100);
N = 10000;
r = random(Td, 1, N);
r(1:10)
actual_mean = mean(r)
actual_std = std(r)
histogram(r)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!