Aurela
Aurela

Reputation: 11

Interpolate datetimes to match size of another array

I have two times: Time_One, Time_Two

I need to make Time_One the same size as Time_Two without deleting any of the existing times. First I convert them into serial date numbers and then interpolate them but it doesn't work. What I'm doing wrong?

Time_One={'05-Apr-2017 12:06:00','05-Apr-2017 12:07:00','05-Apr-2017 12:08:00','05-Apr-2017 12:09:00','05-Apr-2017 12:10:00','05-Apr-2017 12:11:00','05-Apr-2017 12:12:00'};
Time_Two={'05-Apr-2017 12:06:30','05-Apr-2017 12:07:30','05-Apr-2017 12:08:30','05-Apr-2017 12:09:30','05-Apr-2017 12:10:30','05-Apr-2017 12:11:30','05-Apr-2017 12:12:30','05-Apr-2017 12:13:30','05-Apr-2017 12:14:30'};
A = datenum(Time_One)';
B= datenum(Time_Two)';
C=interp1(A,A,B);
D= datetime(C,'ConvertFrom','datenum');

Upvotes: 1

Views: 82

Answers (1)

Wolfie
Wolfie

Reputation: 30046

Your interpolation interp1(A,A,B) isn't doing anything for you, since you've specified A as the input and output of the interpolant.

Instead, I suggest you use a "dummy" x-axis for your interpolation.

C = interp1( linspace(0,1,numel(A)), A, linspace(0,1,numel(B)) );

This will keep your start and end times the same, and the interior points will keep the same spacing relative to each other.

Upvotes: 1

Related Questions