Calculations/ODT-Calculator/+Helper/findNearestValue.m

5 lines
197 B
Matlab

function idx = findNearestValue(array, value)
array = double(array);
[~, idx] = min(abs(array - value)); % Find the index of the element with the minimum absolute difference from value
end