function chi2 = nchisq(x,f,m,s); % nchisq.m 1/23/06 (; removed from lines 12-15) % function chi2 = nchisq(x,f,m,s) % Calculates chi square of the fit of a Normal % distribution with mean m and standard deviation % s to data grouped into the equal size classes % defined by the vector x, with frequencies given % by the vector f ni = length(x) - 1; % number of classes N = sum(f); % total frequency p = 0.5 + 0.5*erf((x-m)/(sqrt(2)*s)); % cum norm prob of class limits pt = p(ni+1) - p(1) % total probability in classes p2 = p(2:ni+1) pc = p2 - p(1:ni) % prob of each class fc = pc*N*pt; % theoretical frequency in each class chi2 = sum((f - fc).^2./fc); % calculate Chi Square