function [res]=eval_Mix_Gauss(x,mu,p_std,numComps)
% EVAL_MIX_GAUSS evaluates whether in the MoG a matching does occurr;
% if yes, it gives the index of that component, otherwise gives 0;

X=size(x,1);
res=zeros(X,1);
goodness=res;
minn=res+200;

for comp=numComps:-1:1%numComps:-1:1
    int1=(mu(:,comp)+2.5*p_std(:,comp));
    int2=(mu(:,comp)-2.5*p_std(:,comp));
    matching=find((x<int1 & x>int2));
    % If two or more components match the signal, we select the nearest component;
    if ~isempty(matching)          
        goodness(matching)=abs(x(matching)-mu(matching,comp));
        OK=find(goodness(matching)<=minn(matching));
        minn(matching(OK))=goodness(matching(OK));
        res(matching(OK))=comp;
    end
end
return;
