By using randn
function I want to create a Gaussian random variable X
such that X ~ N(2,4)
and plot this simulated PDF together with theoretic curve.
Matlab randn
generates realisations from a normal distribution with zero mean and a standard deviation of 1.
Samples from any other normal distribution can simply be generated via:
numSamples = 1000;
mu = 2;
sigma = 4;
samples = mu + sigma.*randn(numSamples, 1);
You can verify this by plotting the histogram:
figure;hist(samples(:));
See the matlab help.