Home > utility > saturate.m

saturate

PURPOSE ^

saturate: Saturate between two level (bound limiter)

SYNOPSIS ^

function output=saturate(x, level)

DESCRIPTION ^

saturate: Saturate between two level (bound limiter)
    Usage:output=saturate(x, level)
        output: output value
        x: input value
        level: level(1)==>lower bound, level(2)==>upper bound

    For example:
        x=linspace(0, 10);
        level=[3 5];
        y=saturate(x, level);
        plot(x, x, x, y, 'o-');
        axis image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function output=saturate(x, level)
0002 %saturate: Saturate between two level (bound limiter)
0003 %    Usage:output=saturate(x, level)
0004 %        output: output value
0005 %        x: input value
0006 %        level: level(1)==>lower bound, level(2)==>upper bound
0007 %
0008 %    For example:
0009 %        x=linspace(0, 10);
0010 %        level=[3 5];
0011 %        y=saturate(x, level);
0012 %        plot(x, x, x, y, 'o-');
0013 %        axis image
0014 
0015 %    Roger Jang, 20071009
0016 
0017 
0018 if nargin<1, selfdemo; return; end
0019 
0020 output=x;
0021 output(find(output<=level(1)))=level(1);
0022 output(find(output>=level(2)))=level(2);
0023 
0024 % ====== selfdemo
0025 function selfdemo
0026 x=linspace(0, 10);
0027 level=[3 5];
0028 y=feval(mfilename, x, level);
0029 plot(x, x, x, y, 'o-');
0030 axis image

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003