Solved – Generating a Gaussian dataset in MATLAB

MATLABnormal distribution

I want to generate a bivariate Gaussian dataset. The dataset includes a total of 800 results drawn randomly from four two-dimensional Gaussian classes with means $(-3,0)'$, $(0,0)'$, $(3,0)'$, and $(6,0)'$, all with the same variance-covariance matrix

$$\Sigma = \pmatrix{0.5 & 0.05 \\ 0.05 &0.5}.$$

How can I do that in MATLAB? I'm not expert in MATLAB.

Best Answer

Statistics Toolbox offers a function to sample from a bivariate Gaussian

% Specific a covariance matrix
SIGMA = [.5 .05; .05 .5 ];

% Generate four bivariate normal distributions with specified means
temp = mvnrnd([-3 0], SIGMA,800);
temp(:,3:4) = mvnrnd([-3 0],SIGMA,800);
temp(:,5:6) = mvnrnd([3 0], SIGMA, 800);
temp(:,7:8) = mvnrnd([6 0], SIGMA, 800);
Related Question