Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
interpolation using last known value

Subject: interpolation using last known value

From: Sören

Date: 5 Sep, 2009 09:20:53

Message: 1 of 4

Hello,

I was wondering if someone could tell me how to use Simulinks 1D-Lookup tables setting: "Use input below" in matlabs command line.

So I have the following two vectors:

x = [1 3 6 8 11 20 22]
y = [2 4 6 8 10 12 14]

And I want to get

xi = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
yi = [2 2 4 4 4 6 6 8 8 8 10 10 10 10 10 10 10 10 10...

I can hardly belief that this function would not exist, but I am having a hard time finding it.

Thanks,
Sören

Subject: interpolation using last known value

From: Bruno Luong

Date: 5 Sep, 2009 09:50:03

Message: 2 of 4

S?ren <seuren83@hotmail.com> wrote in message <1567238853.88851.1252142483756.JavaMail.root@gallium.mathforum.org>...
> Hello,
>
> I was wondering if someone could tell me how to use Simulinks 1D-Lookup tables setting: "Use input below" in matlabs command line.
>
> So I have the following two vectors:
>
> x = [1 3 6 8 11 20 22]
> y = [2 4 6 8 10 12 14]
>
> And I want to get
>
> xi = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
> yi = [2 2 4 4 4 6 6 8 8 8 10 10 10 10 10 10 10 10 10...
>
> I can hardly belief that this function would not exist, but I am having a hard time finding it.
>
> Thanks,
> S?ren

yi = y(floor(interp1(x,1:length(x),xi)))

Subject: interpolation using last known value

From: John D'Errico

Date: 5 Sep, 2009 09:52:01

Message: 3 of 4

S?ren <seuren83@hotmail.com> wrote in message <1567238853.88851.1252142483756.JavaMail.root@gallium.mathforum.org>...
> Hello,
>
> I was wondering if someone could tell me how to use Simulinks 1D-Lookup tables setting: "Use input below" in matlabs command line.
>
> So I have the following two vectors:
>
> x = [1 3 6 8 11 20 22]
> y = [2 4 6 8 10 12 14]
>
> And I want to get
>
> xi = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
> yi = [2 2 4 4 4 6 6 8 8 8 10 10 10 10 10 10 10 10 10...
>
> I can hardly belief that this function would not exist, but I am having a hard time finding it.

histc will identify the element which lies below.

Look at the second output of histc.

Then just use it as an index into y.

John

Subject: interpolation using last known value

From: S?ren Sieberling

Date: 5 Sep, 2009 10:39:02

Message: 4 of 4

Hey,

Both methods work perfect.

Although histc also takes care of repeated values in x, which I had solved differently but its of course cleaner when dealt with in one go.

Thanks a lot to both,

S?ren

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us