function press = pcrpress(a, c, av, cv, vc, maxrank)
% PCRPRESS   Calculate PRESS as a function of the number of factors used
%
%  press = pcrpress(a, c, av, cv, vc, maxrank)
%
% Where:
%
%  press    is the matrix containing press
%  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
%

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

[i, j] = size(vc);
press(i,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;
   press(n, 1) = sum(sum(error .* error));
end
