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
Problem Comments
-
3 Comments
neat! i'd never used time series before
I use timeseries all the time but don't usually use objects. Obviously using object oriented commands is much faster than more manual methods.
https://www.mathworks.com/matlabcentral/cody/problems/44699-prime-product
I created this problem. I think it should be in Indexing I.
Solution Comments
Show commentsProblem Recent Solvers324
Suggested Problems
-
3372 Solvers
-
336 Solvers
-
265 Solvers
-
Are all the three given point in the same line?
415 Solvers
-
435 Solvers
More from this Author50
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!