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

Learn moreOpportunities for recent engineering grads.

Apply TodayUse interpolation to align two time series onto the same time vector.

This is a problem that comes up in Trendy whenever you want to do mathematical operations on two trends (see for example the Ramen-to-Sushi Index).

Given two time series defined by the vector pairs (t1,d1) and (t2,d2), come up with a single new time vector tn such that (tn,d1n) and (tn,d2n) form consistent vector pairs.

Specifically, the new time vector should extend only to portions covered by both series (i.e. no extrapolation). Within this common interval, tn should contain all the time points from both time vectors. With this new time basis, use linear interpolation to generate two new data series.

Example 1:

t1 = [1 3 5] d1 = [2 4 2] t2 = [2 4] d2 = [1 5]

tn = [2 3 4] d1n = [3 4 3] d2n = [1 3 5]

Example 2:

t1 = [1 2 3 4 5] d1 = [2 3 5 6 3] t2 = [2 3.5 4 4.5 5 6] d2 = [3 9 8 2 0 1]

tn = [2 3 3.5 4 4.5 5] d1n = [3 5 5.5 6 4.5 3] d2n = [3 7 9 8 2 0]

70 correct solutions
26 incorrect solutions

Last solution submitted on Jun 08, 2016

1 player likes this problem

1 Comment

Jeffrey Daniels
on 20 Nov 2013

Argh!!! Those last two nodes are the hardest! Where are hey?

2 players like this solution

1 Comment

Jeffrey Daniels
on 20 Nov 2013

Oh Alfonso! What is your secret?!!

1 Comment

Mark Syddall
on 4 May 2012

This is flawed - but matches a previous '47'.
What happens if there is more than a single mismatched leading/trailing value? Say, using: t2 = [3 5 7 11 13 17]; in the third test?

2 Comments

Mark Syddall
on 4 May 2012

What happens if there is more than a single mismatched leading/trailing value?
Say, using:
t2 = [3 5 7 11 13 17];
in the third test?

Freddy
on 4 May 2012

mea culpa, mea mÃ¡xima culpa.

2 Comments