function p=gaussian(mu,Sigma,x) %% x=gaussian(mu,Sigma,N) %% mu, sigma: parameters of the Gaussian %% x: calculate the probability of x if sum(~isnan(x))==0, %% The prob. of the zero-dimension vector is one. p=1; else, %% Non-zero dimension vector good_ind = find(~isnan(x)); %% Compute marginalized Gaussian on features that were detected x = x(good_ind); mu = mu(good_ind); Sigma = Sigma(good_ind,good_ind); ll = length(mu); y = x-mu; d2 = diag(y' * inv(Sigma) * y); p = exp(-d2/2) / sqrt((2*pi)^ll * det(Sigma)); end;