function c = conf(D,x) % c = conf(D,x) % Calculates the confidence that x belongs to the data distribution D, % assuming D is a normal distribution. % Input: D - 2xn or nx2 dimensional data array % x - a single 2D measurement that is to be tested against D. % x is an array of size 2x1 or 1x2 % Output: c - confidence, as a percentage. % This function calls on functions: % [C,a] = prin_comp(D) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [C,a] = prin_comp(D); % Get the mean, a, and covariance, C, of the data. R = chol(C); % Cholesky factorization: C = R'*R [m,n] = size(x); if (m==2)&(n==1) x = x; elseif (m==1)&(n==2) x = x'; else error('x is not a suitable data point'); end xm = x-a; ym = inv(R')*xm; radius = norm(ym); % Integrate numerically % P = gaussian(radius); %c = round((1-P)*100); % Integrate analytically c = (exp(-0.5*radius*radius)*100); c = round(c);