
function gcv = GCV1(x,t)

% GCV1 -- apply soft threshold + compute GCV
%  Usage
%    gcv = GCV1(x,t)
%  Inputs
%    x      input coefficients
%    t      threshold (may be a vector)
%  Outputs
%    gcv    the value of the gcv
%  Description
%    Applies soft-threshold t to all elements of x and computes GCV
%  Note
%    A vector of thresholds may be interesting for plotting

xcol = column(x);
trow = row(t);
N = length(x);
m = length(t);
t = repmat(trow,N,1);
x = repmat(xcol,1,m);

res = abs(x) - t;
N0 = sum(res <= 0);
y = sign(x).*res.*(res >= 0);

if (N0 == 0)
   gcv = 2*0.2^2;
else
   gcv = N * sum((y-x).*(y-x)) ./ N0.^2 ;
end
