function gcv = GCV(x,t)

% GCV -- apply soft threshold + compute GCV
%  Usage
%    gcv = GCV(x,t)
%  Inputs
%    x      input coefficients
%    t      threshold (must be scalar)
%  Outputs
%    gcv    the value of the gcv
%  Description
%    Applies soft-threshold t to all elements of x and computes GCV
%  Note
%    For making a plot of gcv for a given vector of thresholds
%    use GCV1 (1D)

N = length(x);
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 * (norm(y-x) / N0 )^2 ;
end
