Merging different kinds of timeseries data

조회 수: 4 (최근 30일)
Benju Baniya
Benju Baniya 2022년 8월 15일
댓글: Benju Baniya 2022년 8월 18일
Hi, I have two kinds of time series table. One has every 30 minutes high frequency data for each day of the year (Data1) and one has per day sunrise sunset time. How do I merge these data to get the expected result (shown below). For example: the sunrise time on Jan 1 was 7:36 am and sunset tiem was 17:46 pm, I want to repeat this whenever the month is January in data 1 (based on datetime) and so on for other months. I aslo think i have to change sunrise sunset data to hh mm format before using the numeric values. I cannot manually type sunrise and sunset time for each day because there are 30 days in a month and I have 10 years of data. Your help will be much appreaciated.
Data 1
Date Time Year DoY(day of year) Hour NEE
1/1/2009 12:00:00 AM 2009 1 0 1.3023
1/1/2009 12:30:00 AM 2009 1 0.5 1.0569
1/1/2009 1:00:00 AM 2009 1 1 1.0011
1/1/2009 1:30:00 AM 2009 1 1.5 1.3438
1/1/2009 2:00:00 AM 2009 1 2 1.2546
Data 2
DoY Month Sunrise Sunset
1 Jan 736 1746
2 Jan 737 1746
3 Jan 737 1747
4 Jan 737 1748
5 Jan 737 1749
Expected result
Date Time Year DoY Hour NEE Sunrise Sunset
1/1/2009 12:00:00 AM 2009 1 0 1.3023 736 1746
1/1/2009 12:30:00 AM 2009 1 0.5 1.0569 736 1746
1/1/2009 1:00:00 AM 2009 1 1 1.0011 736 1746
1/1/2009 1:30:00 AM 2009 1 1.5 1.3438 736 1746
1/1/2009 2:00:00 AM 2009 1 2 1.2546 736 1746
......
.....
1/2/2009 12:00:00 AM 2009 2 0 1.2345 737 1746
1/2/2009 12:30:00 AM 2009 2 0.5 0.2345 737 1746

답변 (1개)

Asmit Singh
Asmit Singh 2022년 8월 18일
I understand that you want to join the 2 data tables based on the month and day of the year fields .The final merged table can be created by joining the Data1 and Data2 tables. You can read more about joining here.
For creating the month field in Data1 table, you can add a new field "Month" and map it to the name of the month. This can be done as follows
months = {'jan','feb','march','april','may','jun','july','aug','sept','oct','nov','dec'}
data1.Month = month(data1.Datetime) %using your date time field to make a month field
data1.Month = transpose(months(data1.month)) %converting numeric months (1) to strings (jan)
Once this is done you can then join the two tables to get the desired output.
  댓글 수: 1
Benju Baniya
Benju Baniya 2022년 8월 18일
Thank you. Also my month in data 2 is just character vector. So I have to change that character vector to datetime format?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by