From f1f0c65ed63997f9d6f2d011408d63522686912c Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Thu, 26 Nov 2015 10:17:12 +0000
Subject: [PATCH] add iround_os.m to find index and values closest to target
 values in an array, being monotonic or not

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5294 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/iround_os.m | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 crpptbx/iround_os.m

diff --git a/crpptbx/iround_os.m b/crpptbx/iround_os.m
new file mode 100644
index 00000000..92905ffb
--- /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);
-- 
GitLab