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 problem

Subject: interpolation problem

From: Pallav Mishra

Date: 20 Jan, 2013 04:56:08

Message: 1 of 5

Hi,

I am trying to use interp1 to create a linear interpolated hourly and half-hourly price series given the following information:

September 6, 2012, 8am $70
September 6, 2012, 9am $69
September 6, 2012, 12pm $66
September 6, 2012, 3pm $64
September 6, 2012, 4pm $66
September 6, 2012, 7pm $69
September 6, 2012, 8pm $70

Also, I would want to plot the before interpolation and after interpolation information in the same graph. How do I go about it? I would really appreciate inputs on this.

Regards

Pallav

Subject: interpolation problem

From: Matthew Argall

Date: 20 Jan, 2013 05:11:35

Message: 2 of 5

> I am trying to use interp1 to create a linear interpolated hourly and half-hourly price series given the following information:
> Also, I would want to plot the before interpolation and after interpolation information in the same graph.

Convert your time stamps into Julian Dates using the MatLab function juliandates. Then put your monetary numbers into an array.

interpolated_money_values = interp1(money_values, my_times, desired_times);
plot(money_values, my_times, desired_times, interpolated_money_values);

Subject: interpolation problem

From: Pallav Mishra

Date: 20 Jan, 2013 16:37:08

Message: 3 of 5

Matthew Argall <argallmr@gmail.com> wrote in message <9c970eaf-f381-4362-8f2c-7abb27242f56@googlegroups.com>...
> > I am trying to use interp1 to create a linear interpolated hourly and half-hourly price series given the following information:
> > Also, I would want to plot the before interpolation and after interpolation information in the same graph.
>
> Convert your time stamps into Julian Dates using the MatLab function juliandates. Then put your monetary numbers into an array.
>
> interpolated_money_values = interp1(money_values, my_times, desired_times);
> plot(money_values, my_times, desired_times, interpolated_money_values);
...............................

This is what I am doing (not a very nice looking code, and obviously erroneous)-

>> money_values = [70,69,66,64,66,69,70];
>> jd = juliandate(2012,9,6,8,0,0);
>> kd = juliandate(2012,9,6,9,0,0);
>> ld = juliandate(2012,9,6,20,0,0);
>> desired_time = jd:kd-jd:ld;
>> my_time = [juliandate(2012,9,6,8,0,0),juliandate(2012,9,6,9,0,0),juliandate(2012,9,6,12,0,0),juliandate(2012,9,6,15,0,0),juliandate(2012,9,6,16,0,0),juliandate(2012,9,6,19,0,0),juliandate(2012,9,6,20,0,0)];

>> interpolated_money_values = interp1(money_values,my_time,desired_time);

I am getting an error: Error using interp1 (line 257)
The values of X should be distinct.

Subject: interpolation problem

From: TideMan

Date: 20 Jan, 2013 18:48:32

Message: 4 of 5

On Monday, January 21, 2013 5:37:08 AM UTC+13, Pallav Mishra wrote:
> Matthew Argall <argallmr@gmail.com> wrote in message <9c970eaf-f381-4362-8f2c-7abb27242f56@googlegroups.com>...
>
> > > I am trying to use interp1 to create a linear interpolated hourly and half-hourly price series given the following information:
>
> > > Also, I would want to plot the before interpolation and after interpolation information in the same graph.
>
> >
>
> > Convert your time stamps into Julian Dates using the MatLab function juliandates. Then put your monetary numbers into an array.
>
> >
>
> > interpolated_money_values = interp1(money_values, my_times, desired_times);
>
> > plot(money_values, my_times, desired_times, interpolated_money_values);
>
> ...............................
>
>
>
> This is what I am doing (not a very nice looking code, and obviously erroneous)-
>
>
>
> >> money_values = [70,69,66,64,66,69,70];
>
> >> jd = juliandate(2012,9,6,8,0,0);
>
> >> kd = juliandate(2012,9,6,9,0,0);
>
> >> ld = juliandate(2012,9,6,20,0,0);
>
> >> desired_time = jd:kd-jd:ld;
>
> >> my_time = [juliandate(2012,9,6,8,0,0),juliandate(2012,9,6,9,0,0),juliandate(2012,9,6,12,0,0),juliandate(2012,9,6,15,0,0),juliandate(2012,9,6,16,0,0),juliandate(2012,9,6,19,0,0),juliandate(2012,9,6,20,0,0)];
>
>
>
> >> interpolated_money_values = interp1(money_values,my_time,desired_time);
>
>
>
> I am getting an error: Error using interp1 (line 257)
>
> The values of X should be distinct.

Try:
interpolated_money_values = interp1(my_time,money_values,desired_time);
you had the arguments arse about face.

Subject: interpolation problem

From: Pallav Mishra

Date: 20 Jan, 2013 20:19:08

Message: 5 of 5

TideMan <mulgor@gmail.com> wrote in message <424e20da-4fc8-4285-838c-bab1eb6b8ed0@googlegroups.com>...
> On Monday, January 21, 2013 5:37:08 AM UTC+13, Pallav Mishra wrote:
> > Matthew Argall <argallmr@gmail.com> wrote in message <9c970eaf-f381-4362-8f2c-7abb27242f56@googlegroups.com>...
> >
> > > > I am trying to use interp1 to create a linear interpolated hourly and half-hourly price series given the following information:
> >
> > > > Also, I would want to plot the before interpolation and after interpolation information in the same graph.
> >
> > >
> >
> > > Convert your time stamps into Julian Dates using the MatLab function juliandates. Then put your monetary numbers into an array.
> >
> > >
> >
> > > interpolated_money_values = interp1(money_values, my_times, desired_times);
> >
> > > plot(money_values, my_times, desired_times, interpolated_money_values);
> >
> > ...............................
> >
> >
> >
> > This is what I am doing (not a very nice looking code, and obviously erroneous)-
> >
> >
> >
> > >> money_values = [70,69,66,64,66,69,70];
> >
> > >> jd = juliandate(2012,9,6,8,0,0);
> >
> > >> kd = juliandate(2012,9,6,9,0,0);
> >
> > >> ld = juliandate(2012,9,6,20,0,0);
> >
> > >> desired_time = jd:kd-jd:ld;
> >
> > >> my_time = [juliandate(2012,9,6,8,0,0),juliandate(2012,9,6,9,0,0),juliandate(2012,9,6,12,0,0),juliandate(2012,9,6,15,0,0),juliandate(2012,9,6,16,0,0),juliandate(2012,9,6,19,0,0),juliandate(2012,9,6,20,0,0)];
> >
> >
> >
> > >> interpolated_money_values = interp1(money_values,my_time,desired_time);
> >
> >
> >
> > I am getting an error: Error using interp1 (line 257)
> >
> > The values of X should be distinct.
>
> Try:
> interpolated_money_values = interp1(my_time,money_values,desired_time);
> you had the arguments arse about face.

-----------------

Great! Thanks, this works well!

Tags for this Thread

No tags are associated with 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