“ In the data we have collected, some data is arranged in absolute time coordinates, such as rainfall, earthquakes, temperature, and so on.
So, how can we calculate and adjust absolute time coordinates?”
Data Reading
-
When reading data, methods like
readtimetablecan be used to retain the time data format; -
If the time format is not retained during data reading, functions such as
duration,hours,minutes, etc., can be used to construct it separately in subsequent processes.
Data Manipulation
For example, with a time coordinate like 11:10:09, logical operations can be directly performed in calculations, such as OR (|), AND (&), NOT (~). An example is as follows:
Objective: Extract all data values within the time range of 11:00:00-11:10:00 and sum them up.
value = data(t>hours(11) & t<hours(11)+minutes(10)) ;sum_value = sum(value);% data is the dataset, t is the corresponding sampling time point% The functions hours and minutes convert input parameters to time% The time range is left-open, right-open interval% The code means: through logical operations on the time range, we obtain the coordinates of data points that meet the conditions% Use the data coordinates to extract data from data.
When performing logical operations, due to the existence of time conversion functions like hours, minutes, and second, we can set known time series and then perform value filtering and calculations. An example is as follows:
Objective: Obtain values starting from 11:00:00, taken at equal intervals of 10 minutes until 12:00:00.
i = hours(11) : minutes(10) : hours(12) :
The code result is as follows:
As shown in the figure above, after taking values at equal intervals of time, we obtain a special time format: a decimal, but the unit is hours.
This special time format is called decimal time. The decimal time representation uses the idea of normalization (in my understanding) to segment time. For example, we represent a full day of 24 hours as 1, dividing each scale within 24 hours into this length.
For example:
11:00:00→11/24=0.4583
(11:00:00 is represented as 0.4583)
11:11:11→11/24+11/60/24+11/60/60/24=0.4661
(11:11:11 is represented as 0.4661)
Thus, based on the above ideas, we can achieve fine manipulation of time data.