Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Gaussian random variable with MATLAB

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.

like image 520
Crunkyyy Avatar asked Apr 09 '26 13:04

Crunkyyy


1 Answers

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.

like image 99
Maurits Avatar answered Apr 12 '26 04:04

Maurits