Cody

# Problem 263. Nonuniform quantizer as a piecewise constant function

Solution 1590605

Submitted on 24 Jul 2018
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
assert(isequal(nonuniformQuantizer(-23), -3.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test1 (line 1) assert(isequal(nonuniformQuantizer(-23), -3.5));

2   Fail
assert(isequal(nonuniformQuantizer(0), 0.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test2 (line 1) assert(isequal(nonuniformQuantizer(0), 0.5));

3   Fail
assert(isequal(nonuniformQuantizer(1.1), 1.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test3 (line 1) assert(isequal(nonuniformQuantizer(1.1), 1.5));

4   Fail
assert(isequal(nonuniformQuantizer(2.9), 1.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test4 (line 1) assert(isequal(nonuniformQuantizer(2.9), 1.5));

5   Fail
assert(isequal(nonuniformQuantizer(-Inf), -3.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test5 (line 1) assert(isequal(nonuniformQuantizer(-Inf), -3.5));

6   Fail
assert(isequal(nonuniformQuantizer(Inf), 3.5));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test6 (line 1) assert(isequal(nonuniformQuantizer(Inf), 3.5));

7   Fail
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)));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test7 (line 5) assert(isequal(y, nonuniformQuantizer(x)));

8   Fail
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')));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test8 (line 5) assert(isequal(y', nonuniformQuantizer(x')));

9   Fail
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))));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test9 (line 6) nonuniformQuantizer(reshape(x,3,6))));

10   Fail
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))));

Index exceeds array bounds. Error in nonuniformQuantizer (line 9) ind=logical(x>=r(i)); Error in Test10 (line 6) nonuniformQuantizer(reshape(x,1,6,3))));