Cody

# Problem 176. Nearest

Solution 474169

Submitted on 17 Jul 2014 by Abdullah Caliskan
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)

k = 0.4000 idx = 4 value = 6

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

k = 4.6000 idx = 1 value = 1

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

k = 0 idx = 3 value = 3 k = 0 idx = 6 value = 6 k = 0 idx = 9 value = 9

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

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

k = 3 idx = 1 value = 9 k = 2 idx = 1 value = 9 k = 1 idx = 1 value = 9 k = 0 idx = 1 value = 9 k = 1 idx = 1 value = 9 k = 2 idx = 1 value = 9 k = 3 idx = 1 value = 9 k = 3 idx = 2 value = 16 k = 2 idx = 2 value = 16 k = 1 idx = 2 value = 16 k = 0 idx = 2 value = 16

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!