% plotGMM1d(weights, means, variances, resolution, zero)
% 
% plots a 1d Gaussian mixture distribution
% copyright (c) 2008 by thilo stadelmann, stadelmann@informatik.uni-marburg.de

function jLine = plotGMM1d(dimensions, mixChecked, weights, means, variances, allvariances, resolution,zero)
    
    M = length(variances);
    minx = [];
    maxx = [];
    
    for m = 1:M
        if(mixChecked(m) == 1)
            deltaX = sqrt(-2.0 .* variances .* (repmat(log(zero),length(variances),1) + 0.5*log((2*pi)^dimensions*prod(allvariances(m, :))))); 
            minx(m) = min(means-deltaX);
            maxx(m) = max(means+deltaX);
        end
    end
       
    minX = min(minx);
    maxX = max(maxx);

    t = (abs(minX)+abs(maxX)) / resolution;
    x = minX: t : maxX;
    
    y = gmm1d(x, dimensions, mixChecked, weights, means, variances, allvariances);
    jLine = plot(x, y, 'LineWidth', 2,'XDATA', x, 'YDATA',y);
     % jLine = plot(x, y, 'XDATA', x, 'YDATA',y);
    set(gca, 'Box', 'on');
