# Problem 652. Put two time series onto the same time basis

Use 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]```

### Solution Stats

49.94% Correct | 50.06% Incorrect
Last Solution submitted on Aug 21, 2024

Show comments

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!