How to merge time series data in a sum?

15 次查看(过去 30 天)
I have 2 data sets with corresponding timestamps. The timestamps are not the same for each data set (different dimensions). For simplicity, let's say one set is daily and the other contains points for every other day.It is important to know that both data sets measure the same information and I would like to merge the 2 sets. This means creating a new data set with a combined timeline and adding the data. I do not want to concatenate the time series, but take that data an obtain a daily sum. After doing much research, I have not seen this done with timeseries objects. I came across timetable objects, which looked promising. But after agregating the data, I only got one table (good) with 2 variables (bad). I would like to unify the 2 time series.
I started with collect data from a CSV and creating a table. From this table, I would like to create a unified timeseries or timetable object.
The image above shows the tables that I'm starting with (some information has been redacted). I will start with simply handling the "FundsIn" data. These tables have already been cleared of the "FundsOut" data. The date and "FundsIn" were then made into timeseries.
I was not able to merge these timeseries because their dimensions did not agree (which I expected). So I tried timetables.
As you can see, I've directly transferred the data into a timetable. The final timetable "ttbl3" is the combined timetable. I created this object by aggregating the daily values, now I would like to sum Var1_ttble and Var1_ttbl2. Is this possible to do in timetable form beforehand? Or must I take the new synchronised variables and sum them now? The whole reasons for this is because I need the data synchronised. I wish to know the total funds in for any given day. I hope I have been thorough enough and any help would be appreciated!

回答(1 个)

Ravi
Ravi 2023-10-14
Hi Jessie Atamanchuk,
I understand that you are trying to combine the two timetables into a new timetable with two columns such that the first column represents the timestamp, and the second column represents the total funds.
You can use the synchronize function to combine the timetables matching against the timestamp, and later add the third column as sum of “Var1_ttbl1” and “Var1_ttbl2”.
Example:
ttbl3 = synchronize (ttbl1, ttbl2, 'first', 'Time');
ttbl3.total = ttbl3.Var1_ttbl1 + ttbl3.Var1_ttbl2
When there can exist multiple timestamps in the timetables, synchronize helps to match the corresponding timestamps.
If you want to learn more about synchronize, kindly refer to the below mentioned link.
  • synchronize: https://in.mathworks.com/help/matlab/ref/timetable.synchronize.html
Hope the above-mentioned approach followed by resources answer your question.

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by