function tstar = aveknt(t,k)
%AVEKNT Knot averages.
%
%   AVEKNT(T,K)  returns the averages of successive  K-1  knots, i.e., 
%   the points 
%
%       TSTAR(i) = ( T_{i+1} + ... + T_{i+K-1} ) / (K-1)
%
%   recommended as good interpolation point choices when interpolating
%   from  S_{K,T} .
%
%   For example, with  k  and the increasing sequence  breaks  given,
%   the statements
%
%      t = augknt(breaks,k); x = aveknt(t);
%      sp = spapi( t , x, sin(x) );
%
%   provide a spline interpolant to the sine function on the interval
%   [breaks(1) .. breaks(end)] .
%
%   See also SPAPIDEM, OPTKNT, APTKNT, CHBPNT.

%   Carl de Boor 24 may 89
%   cb : 22 mar 91 (program around a MATLAB discontinuity)
%   cb :  9 may 95 (use .' instead of ')
%   cb :  5 mar 96 (use reshape etc.)
%   cb :  5 oct 97 (replace use of ANS, to help compilation)
%   cb :  4 may 98 (standardize help)
%   cb : 11 dec 98 (use repmat)
%   cb : 14 feb 99 (handle tau of length k)
%   Copyright 1987-2000 by C. de Boor and The MathWorks, Inc.
%   $Revision: 1.11 $

t = t(:); n = length(t)-k;
if k<2, error('The second argument must be at least 2 .')
elseif n<0, error('There must be at least K knots.')
elseif k==2, tstar = reshape(t(1+[1:n]),1,n);
else
   temp = repmat(t,1,k-1);
   temp = sum(reshape([temp(:);zeros(k-1,1)],n+k+1,k-1).')/(k-1);
   tstar = temp(1+[1:n]);
end
