Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Interpolation
Date: Mon, 16 Jul 2007 22:38:26 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 30
Message-ID: <f7gs12$7ja$1@fred.mathworks.com>
References: <f7g0b4$sbc$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
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 1184625506 7786 172.30.248.35 (16 Jul 2007 22:38:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 16 Jul 2007 22:38:26 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader eê64(-¸†
Xref: news.mathworks.com comp.soft-sys.matlab:419418



> Does anyone have the code to do interpolation so that it always takes the lower value.
>
> For example, here is a known distribution
> X Y
> 0.01 200
> 0.02 500
> 0.03 700
> 0.04 900
> 0.05 1000
> ... ...
> 0.99 20000
> 1 20300 
> 
> if x1=0.015, then y1=200; x1=0.019, y1=200; x1=0.039, y1=700;...


In your example, its simple.

ind = floor(x1/0.1);
y1 = Y(ind);

If X is not so simply spaced, then you can use
interp1.

ind = floor(interp1(X,1:length(X),x1,'linear'));
y1 = Y(ind);

HTH,
John