function fitv = pcrfitv(a, c, av, cv, vc, maxrank)
% PCRFITV  Calculate the fit to a validation set with given eigenvectors.
%
%  fitv = pcrfitv(a, c, av, cv, vc, maxrank)
%
% Where:
%
%  fit      is the matrix containing information on the fit
%  a        is the training set absorbance matrix
%  c        is the training set concentration matrix
%  av       is the validation set absorbance matrix
%  cv       is the validation set concentration matrix
%  vc       is the matrix containing the eigenvectors (factors)
%  maxrank  is optional limit to the number of factors tested
%
% The first columns of fitv 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);
fitv(i, (k + 1)) = 0;
if nargin == 6, i = maxrank; end
for n = 1:i;
   proj = vc(:,1:n)' * a;
   error = (c * proj' * inv(proj * proj') * vc(:,1:n)' * av) - cv;
fitv(n, :) = [std(error') mean(std(error'))];
end
