%% Map Floating-Point Scalars to Integers
% Map floating-point scalars in [-1, 1] to uint8 (unsigned) integers. Produce a staircase plot. The horizontal axis ranges from -1 to 1 and the vertical axis from 0 to 7 (i.e., 2^3-1).

u = -1:0.01:1;
y = uencode(u,3);
plot(u,y,'.')

%
% Look at saturation effects when you underspecify the peak value for the input.

u = -2:0.5:2;
y = uencode(u,5,1)

%
% Specify you want signed output.

u = -2:0.5:2;
y = uencode(u,5,2,'signed')

% Copyright 2015 The MathWorks, Inc.