function out = thresh(vec, th, mn, mx)

%  function out = thresh(vec, th, mn, mx)
%
%  Threshold the elements of a vector
%
%     
%  mx           _____________ 
%              |
% output       |
%              |
%  mn  ________|
%
%             th
%        input


if(nargin < 1)
  error('thresh(): must supply a vector');
end;

if(nargin < 2)
  th = 0;
end;
if(nargin < 3)
  mn = 0;
end;
if(nargin < 4)
  mx = 1;
end;

out = mn * ones(size(vec));
elems = find(vec > th);
if(~isempty(elems))
  out(elems) = mx * ones(length(elems),1);
end;


