clamp.m 303 B

123456789101112
  1. function Y = clamp( X, min, max )
  2. % CLAMP restricts values of 'X' to be within the range from 'min' to 'max'.
  3. %
  4. % Y = clamp( X, min, max )
  5. %
  6. % (C) Rafal Mantiuk <mantiuk@gmail.com>
  7. % This is an experimental code for internal use. Do not redistribute.
  8. Y = X;
  9. Y(X<min) = min;
  10. Y(X>max) = max;
  11. end