Cody

Solution 77585

Submitted on 17 Apr 2012 by Kuifeng
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 = 3:10; y = 5.6; [v,i] = nearVal(x,y); assert(v == 6 && i == 4)

v = 0.4000 id = 4 v = 6

2   Pass
%% x = [1 1000]; y = 5.6; [v,i] = nearVal(x,y); assert(v == 1 && i == 1)

v = 4.6000 id = 1 v = 1

3   Pass
%% x = 1:500; y = 3:3:9; [v,i] = nearVal(x,y); assert(all(v == y & i == y))

v = 0 id = 3 v = 0 id = 6 v = 0 id = 9 v = 3 6 9

4   Pass
%% x = 1; y = 1:100; [v,i] = nearVal(x,y); assert(all(v == 1 & i == 1))

v = 0 id = 1 v = 1 id = 1 v = 2 id = 1 v = 3 id = 1 v = 4 id = 1 v = 5 id = 1 v = 6 id = 1 v = 7 id = 1 v = 8 id = 1 v = 9 id = 1 v = 10 id = 1 v = 11 id = 1 v = 12 id = 1 v = 13 id = 1 v = 14 id = 1 v = 15 id = 1 v = 16 id = 1 v = 17 id = 1 v = 18 id = 1 v = 19 id = 1 v = 20 id = 1 v = 21 id = 1 v = 22 id = 1 v = 23 id = 1 v = 24 id = 1 v = 25 id = 1 v = 26 id = 1 v = 27 id = 1 v = 28 id = 1 v = 29 id = 1 v = 30 id = 1 v = 31 id = 1 v = 32 id = 1 v = 33 id = 1 v = 34 id = 1 v = 35 id = 1 v = 36 id = 1 v = 37 id = 1 v = 38 id = 1 v = 39 id = 1 v = 40 id = 1 v = 41 id = 1 v = 42 id = 1 v = 43 id = 1 v = 44 id = 1 v = 45 id = 1 v = 46 id = 1 v = 47 id = 1 v = 48 id = 1 v = 49 id = 1 v = 50 id = 1 v = 51 id = 1 v = 52 id = 1 v = 53 id = 1 v = 54 id = 1 v = 55 id = 1 v = 56 id = 1 v = 57 id = 1 v = 58 id = 1 v = 59 id = 1 v = 60 id = 1 v = 61 id = 1 v = 62 id = 1 v = 63 id = 1 v = 64 id = 1 v = 65 id = 1 v = 66 id = 1 v = 67 id = 1 v = 68 id = 1 v = 69 id = 1 v = 70 id = 1 v = 71 id = 1 v = 72 id = 1 v = 73 id = 1 v = 74 id = 1 v = 75 id = 1 v = 76 id = 1 v = 77 id = 1 v = 78 id = 1 v = 79 id = 1 v = 80 id = 1 v = 81 id = 1 v = 82 id = 1 v = 83 id = 1 v = 84 id = 1 v = 85 id = 1 v = 86 id = 1 v = 87 id = 1 v = 88 id = 1 v = 89 id = 1 v = 90 id = 1 v = 91 id = 1 v = 92 id = 1 v = 93 id = 1 v = 94 id = 1 v = 95 id = 1 v = 96 id = 1 v = 97 id = 1 v = 98 id = 1 v = 99 id = 1 v = Columns 1 through 10 1 1 1 1 1 1 1 1 1 1 Columns 11 through 20 1 1 1 1 1 1 1 1 1 1 Columns 21 through 30 1 1 1 1 1 1 1 1 1 1 Columns 31 through 40 1 1 1 1 1 1 1 1 1 1 Columns 41 through 50 1 1 1 1 1 1 1 1 1 1 Columns 51 through 60 1 1 1 1 1 1 1 1 1 1 Columns 61 through 70 1 1 1 1 1 1 1 1 1 1 Columns 71 through 80 1 1 1 1 1 1 1 1 1 1 Columns 81 through 90 1 1 1 1 1 1 1 1 1 1 Columns 91 through 100 1 1 1 1 1 1 1 1 1 1

5   Pass
%% x = (3:5).^2; y = 6:16; [v,i] = nearVal(x,y); assert(isequal(v,[9 9 9 9 9 9 9 16 16 16 16]) && isequal(i,[1 1 1 1 1 1 1 2 2 2 2]))

v = 3 id = 1 v = 2 id = 1 v = 1 id = 1 v = 0 id = 1 v = 1 id = 1 v = 2 id = 1 v = 3 id = 1 v = 3 id = 2 v = 2 id = 2 v = 1 id = 2 v = 0 id = 2 v = Columns 1 through 10 9 9 9 9 9 9 9 16 16 16 Column 11 16