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
49 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Can anyone help me with this please
1 Commento
the cyclist
il 18 Set 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.
Risposte (2)
Ravi Narasimhan
il 18 Set 2021
The documentation for the randn function may be of interest.
0 Commenti
Walter Roberson
il 18 Set 2021
Modificato: Walter Roberson
il 18 Set 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 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!