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