### Tags: 3andxi, 6if, extrapolation, interpolation, isi, matlab, programming, vectorsx

# Interpolation and extrapolation

On Programmer » Matlab

1,666 words with 1 Comments; publish: Wed, 07 May 2008 04:53:00 GMT; (200156.25, « »)

Hello,

my problem is:

i have this vectors:

X=[ 1 2 3 4];

Y=[ 5 15 16 3];

and

XI=[ 0 0.5 1.5 3.5 4.3 6];

if I do:

YI=interp1(X,Y,XI,'nearest','extrap');

I get the values of YI on XI points according to the nearest

interpolation,but, what could i do if i'm looking for a pchip

interpolation for the elements of XI are inside the interval [1 4]

and a nearest interpolation for the elements are outside this

interval?

i know that i can divide the XI vector into two parts depending on

if the element of XI is either inside or outside interval [1 4], but

do you know a easy way?

thank you in advance por your help!!

*http://matlab.todaysummary.com/q_matlab_31972.html*

All Comments

Leave a comment...

- 1 Comments
- Jesus Castellanos wrote:
>

> Hello,

> my problem is:

> i have this vectors:

> X=[ 1 2 3 4];

> Y=[ 5 15 16 3];

> and

> XI=[ 0 0.5 1.5 3.5 4.3 6];

> if I do:

> YI=interp1(X,Y,XI,'nearest','extrap');

> I get the values of YI on XI points according to the nearest

> interpolation,but, what could i do if i'm looking for a pchip

> interpolation for the elements of XI are inside the interval [1 4]

> and a nearest interpolation for the elements are outside this

> interval?

> i know that i can divide the XI vector into two parts depending on

> if the element of XI is either inside or outside interval [1 4],

> but

> do you know a easy way?

Simplest is to clip.

YI=interp1(X,Y,min(max(X),max(min(X),XI)

),'pchip');

HTH,

John D'Errico

#1; Wed, 07 May 2008 04:54:00 GMT

- Jesus Castellanos wrote: