function [fcal, f] = pcrcal(a, c, vc, n)
% PCRCAL  Perform P-matrix type quant by cross-correlation 
%
%           PCRCAL does the P-matrix type quant by cross-correlation
%           in the chosen abstract vector space.
%
%  fcal = pcrcal(a, c, vc, n)    or    [fcal, f] = fcalf(a, c, vc, n)
%
% Where:
%
%  fcal is the calibration matrix
%  f    is the matrix containing the calibration in factor space
%  a    is the absorbance matrix
%  c    is the concentration matrix
%  vc   is the matrix containing the factors (eigenvectors)
%  n    is the number of factors to use in the calibration
%
% The concentrations of components in unknown spectra can be
% calculated if the unknown absorbances are set up as a vector (for 1
% unknown) or a matrix (for multiple unknowns).  The unknown matrix
% can have any available name.  For example call it "u".  The 
% unknown concentrations are then given by fcal * u.
%

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

[t, maxrank] = size(vc);
if n > maxrank, n = maxrank, end;
vc = vc(:, 1:n);
proj = (vc' * a);
f = c * proj' * inv(proj * proj');
fcal = f * vc';
