Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Interpolation
Date: Tue, 17 Jul 2007 18:51:34 +0000 (UTC)
Organization: Nationwide Mutual Insurance Co.
Lines: 15
Message-ID: <f7j33m$5oc$1@fred.mathworks.com>
References: <f7g0b4$sbc$1@fred.mathworks.com> <f7gs12$7ja$1@fred.mathworks.com> <f7j18o$6t0$1@fred.mathworks.com> <f7j1s9$g9m$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-00-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1184698294 5900 172.30.248.35 (17 Jul 2007 18:51:34 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Jul 2007 18:51:34 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 0¢\^†
Xref: news.mathworks.com comp.soft-sys.matlab:419562



Thanks for the prompt response.

I realized the error in my code as x1 is supposed to be a vector. So I changed the code to be:
===============================================
function y1=NoInterp(x,Y,xd)
xd(xd<min(x))=min(x);
xd(xd>max(x))=max(x);
ind = floor(interp1(x,1:length(x),xd,'linear'));
y1 = Y(ind);
================================================

And it works fine now.

Thanks,
Stephen