Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 176. Nearest

Created by @bmtran

Description

Find the value and index of the element in vector x that is nearest to value y. y should be able to be a vector.

Example

    x = 3:10;
    y = 5.6
    [v,i] = nearVal(x,y);
    v = 6;
    i = 4;

Tags

Problem Group

Solution Statistics

109 correct solutions 211 incorrect solutions
Last solution submitted on Aug 17, 2014