diff --git a/crpptbx/iround_os.m b/crpptbx/iround_os.m new file mode 100644 index 0000000000000000000000000000000000000000..92905ffbc13fa1a152cae28e32502081414f1725 --- /dev/null +++ b/crpptbx/iround_os.m @@ -0,0 +1,16 @@ +function [is,sigi]=iround_os(sig,val) +% Given two arrays sig and val, for each element in val +% returns the index and value of the nearest element in sig. +% +% sig and/or val can be non-monotonic +% +% Example: +% +% >> [i,sigi]=iround_OS(sig,val); +% +% +% +for j=1:length(val) + [s(j),is(j)]=min(abs(sig-val(j))); +end +sigi=sig(is);