Cody

# Problem 176. Nearest

Solution 289058

Submitted on 25 Jul 2013 by Chintan
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)

``` a = 1 b = 4 ```

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

``` a = 1 b = 1 ```

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

``` a = 1 b = 3 a = 1 b = 6 a = 1 b = 9 ```

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

``` a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 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]))

``` a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 1 a = 1 b = 2 a = 1 b = 2 a = 1 b = 2 a = 1 b = 2 ```