Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

18Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
assert(isequal(nonuniformQuantizer(-23), -3.5));
ans =
   -3.5000
2
Pass
 
%%
assert(isequal(nonuniformQuantizer(0), 0.5));
ans =
    0.5000
3
Pass
 
%%
assert(isequal(nonuniformQuantizer(1.1), 1.5));
ans =
    1.5000
4
Pass
 
%%
assert(isequal(nonuniformQuantizer(2.9), 1.5));
ans =
    1.5000
5
Pass
 
%%
assert(isequal(nonuniformQuantizer(-Inf), -3.5));
ans =
   -3.5000
6
Pass
 
%%
assert(isequal(nonuniformQuantizer(Inf), 3.5));
ans =
    3.5000
7
Pass
 
%%
x = -4.0:0.5:4.5;
y = [-3.5 -3.5 -1.5 -1.5 -1.5 ...
    -1.5 -0.5 -0.5 0.5 0.5 1.5 ...
    1.5 1.5 1.5 3.5 3.5 3.5 3.5];
assert(isequal(y, nonuniformQuantizer(x)));
ans =
  Columns 1 through 10
   -3.5000   -3.5000   -1.5000   -1.5000   -1.5000   -1.5000   -0.5000   -0.5000    0.5000    0.5000
  Columns 11 through 18
    1.5000    1.5000    1.5000    1.5000    3.5000    3.5000    3.5000    3.5000
8
Pass
 
%%
x = -4.0:0.5:4.5;
y = [-3.5 -3.5 -1.5 -1.5 -1.5 ...
    -1.5 -0.5 -0.5 0.5 0.5 1.5 ...
    1.5 1.5 1.5 3.5 3.5 3.5 3.5];
assert(isequal(y', nonuniformQuantizer(x')));
ans =
   -3.5000
   -3.5000
   -1.5000
   -1.5000
   -1.5000
   -1.5000
   -0.5000
   -0.5000
    0.5000
    0.5000
    1.5000
    1.5000
    1.5000
    1.5000
    3.5000
    3.5000
    3.5000
    3.5000
9
Pass
 
%%
x = -4.0:0.5:4.5;
y = [-3.5 -3.5 -1.5 -1.5 -1.5 ...
    -1.5 -0.5 -0.5 0.5 0.5 1.5 ...
    1.5 1.5 1.5 3.5 3.5 3.5 3.5];
assert(isequal(reshape(y,3,6), ...
    nonuniformQuantizer(reshape(x,3,6))));
ans =
   -3.5000   -1.5000   -0.5000    0.5000    1.5000    3.5000
   -3.5000   -1.5000   -0.5000    1.5000    1.5000    3.5000
   -1.5000   -1.5000    0.5000    1.5000    3.5000    3.5000
10
Pass
 
%%
x = -4.0:0.5:4.5;
y = [-3.5 -3.5 -1.5 -1.5 -1.5 ...
    -1.5 -0.5 -0.5 0.5 0.5 1.5 ...
    1.5 1.5 1.5 3.5 3.5 3.5 3.5];
assert(isequal(reshape(y,1,6,3), ...
    nonuniformQuantizer(reshape(x,1,6,3))));
ans(:,:,1) =
   -3.5000   -3.5000   -1.5000   -1.5000   -1.5000   -1.5000
ans(:,:,2) =
   -0.5000   -0.5000    0.5000    0.5000    1.5000    1.5000
ans(:,:,3) =
    1.5000    1.5000    3.5000    3.5000    3.5000    3.5000