View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 1.71 KB File ID: #33808 Version: 1.0




CLIP2 limits the values in an array.

| Watch this File

File Information

CLIP2 limits the values in an array
   Y = CLIP2(A,x_min,x_max) generates an array Y where values outside
   the limits (x_min, x_max) are clipped to interval edges. A is a matrix
   and x_min and x_max are scalar values. The size of Y is the same size
   as A.
   Y = CLIP2(A,x_min,x_max,'DisplayAsNans') is like CLIP2(A,x_min,x_max)
   but values outside the limits are replaced to nans.

   For example,
       x = (1:100)'; x_min = 15; x_max = 47;
       y = clip2(x,x_min,x_max)
       x = ceil(100*rand(10)); x_min = 5; x_max = 25;
       y = clip2(x,x_min,x_max)

       t = (0:1e-2:5)'; x = 3.5*sin(2*pi*t); x_min =
       0; x_max = max(x); y =clip2(x,x_min,x_max,'DisplayAsNans')

   CLIP2 is a modification from NUMPY's (Python extension module)
   clip function.


This file inspired Clip.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
18 Nov 2011 Mikko Leppänen

Yes Jan, you are correct. Furthermore, this way of coding, it generates somewhat faster code.

Comment only
17 Nov 2011 Jan Simon

Jan Simon (view profile)

You can omit the reshaping and operate on the input A directly instead of the vector x.

Comment only

Contact us