Cody

# Problem 176. Nearest

Solution 804885

Submitted on 12 Jan 2016 by Zikobrelli
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)

i = [] v = [] z = 4 i = 4

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

i = [] v = [] z = 1 i = 1

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

i = [] v = [] z = 3 i = 3 z = 6 i = 3 6 z = 9 i = 3 6 9

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

i = [] v = [] z = 1 i = 1 z = 1 i = 1 1 z = 1 i = 1 1 1 z = 1 i = 1 1 1 1 z = 1 i = 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Column 30 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 31 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 32 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 33 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 34 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 35 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 36 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 37 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 38 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 39 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 40 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 41 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 42 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 43 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 44 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 46 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 47 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 49 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 30 through 51 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 1 i = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 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]))

i = [] v = [] z = 1 i = 1 z = 1 i = 1 1 z = 1 i = 1 1 1 z = 1 i = 1 1 1 1 z = 1 i = 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 z = 1 i = 1 1 1 1 1 1 1 z = 2 i = 1 1 1 1 1 1 1 2 z = 2 i = 1 1 1 1 1 1 1 2 2 z = 2 i = 1 1 1 1 1 1 1 2 2 2 z = 2 i = 1 1 1 1 1 1 1 2 2 2 2

### Community Treasure Hunt

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

Start Hunting!
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}