Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Interpolation
Date: Tue, 17 Jul 2007 18:30:33 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 34
Message-ID: <f7j1s9$g9m$1@fred.mathworks.com>
References: <f7g0b4$sbc$1@fred.mathworks.com> <f7gs12$7ja$1@fred.mathworks.com> <f7j18o$6t0$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 1184697033 16694 172.30.248.35 (17 Jul 2007 18:30:33 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Jul 2007 18:30:33 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader eê64(-¸†
Xref: news.mathworks.com comp.soft-sys.matlab:419557



> I try to write this as a function:

===========================================================
function y1=NoInterp(x,Y,x1)

if x1 < min(x)
      x1=min(x);
elseif x1>max(x)
     x1=max(x);
end

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

===========================================================

> When x1 is in the range, the function runs OK. When x1 is out of range, the > if statement I added to your code doesn't seem to work properly and the
> function fails. Could you help me figure out what's wrong here?


The problem is that if does not work as you are using
it. An if statement is not "vectorized".

However, why bother? Min and max ARE vectorized.

What does this do for you?

  x1 = min(x1,max(x));

How about this?

  x1 = max(x1,min(x));

John