function [closest, idx2,delta] = find_nearest_value(vector_to_search,value)

tmp = abs(vector_to_search-value);
[delta idx2] = min(tmp); %index of closest value
closest =vector_to_search(idx2); %closest value