function fit = pcrfit(a, c, vc, maxrank)
% PCRFIT  Calculate the fit to the standards  with eigenvectors.
%
%  fit = pcrfit(a, c, vc, maxrank)
%
% Where:
%
%  fit      is the matrix containing information on the fit
%  a        is the absorbance matrix
%  c        is the concentration matrix
%  vc       is the matrix containing the eigenvectors (factors)
%  maxrank  is optional limit to the number of factors tested
%
% The first columns of fit contain the std's of the fit for each
% component.  The last column contains the mean for all components.
%

% Copyright (c) 1989-92 by The MathWorks, Inc.

[i, j] = size(vc);
[k, l] = size(c);
fit(i, (k + 1)) = 0;
if nargin == 4, i = maxrank; end
for n = 1:i;
   proj = vc(:,1:n)' * a;
   error = (c * proj' * inv(proj * proj') * vc(:,1:n)' * a) - c;
fit(n, :) = [std(error') mean(std(error'))];
end
