% In the array or vector A find the element closest to the value b % Returns the element as well as the row and column indices % Syntax [value,pos] = findnear(A,b) function [value,pos] = FindNear(A,b) dist = abs(A-b); [pos(1),pos(2)] = find(dist == repmat(min(dist(:)),size(dist)));% The minimum of the distance vector value = A(pos(1),pos(2));