Cody

Solution 1720190

Submitted on 4 Feb 2019 by Nikolaos Nikolaou
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   Pass
x = [1:1:5]; a = 4.3; y_correct = 4; assert(isequal(nearestNumber(x,a),y_correct))

y1 = 4.3000 4.3000 4.3000 4.3000 4.3000 y2 = 3.3000 2.3000 1.3000 0.3000 0.7000 y3 = 4 y = 4

2   Pass
x = [2 4 5 6 8 10]; a = 4.6; y_correct = 5; assert(isequal(nearestNumber(x,a),y_correct))

y1 = 4.6000 4.6000 4.6000 4.6000 4.6000 4.6000 y2 = 2.6000 0.6000 0.4000 1.4000 3.4000 5.4000 y3 = 3 y = 5

3   Pass
x = [-2 -3 -1 0]; a = -3.1; y_correct = -3; assert(isequal(nearestNumber(x,a),y_correct))

y1 = -3.1000 -3.1000 -3.1000 -3.1000 y2 = 1.1000 0.1000 2.1000 3.1000 y3 = 2 y = -3