MATLAB: Gaussian Mixture Model using gmdistribution

fitdistfitgmgaussiangmdistributionMATLAB

Hi I am trying to create a GM model with 2 components in 1 dimension. I have both the means and covariances as well as the mixing proportions. Ia am getting an error 'The shared diagonal covariance must be a row vector with the same number of columns as MU.' when I try to use gmdistribution function. How do I set sigma up so it can be used in this function. My code is as follows:
mu = [6.25 ;4.33];
sigma = [0.52,0.37];
p = [0.40,0.60];
gm = gmdistribution(mu, sigma, p);

Best Answer

Try this:
>> mu=[6.25;4.33];
>> sigma=reshape([0.52 0.37],1,1,2); % third dimesion required, note that sigma are VARIANCES per doc gmdistribution
>> p=[0.4 0.6];
>> gm = gmdistribution(mu,sigma,p);
>> x=(0:.1:15).';
>> plot(x,pdf(gm,x)),grid