| Contents | Index |
Create timeseries object
Time series are data vectors sampled over time, in order, often at regular intervals. They are distinguished from randomly sampled data that form the basis of many other data analyses. Time series represent the time-evolution of a dynamic population or process. The linear ordering of time series gives them a distinctive place in data analysis, with a specialized set of techniques. Time series analysis is concerned with:
Identifying patterns
Modeling patterns
Forecasting values
ts = timeseries creates an empty time-series object.
ts = timeseries(data) creates the time-series object using the specified data.
ts = timeseries(tsname) creates the time-series object using the name, tsname, for the time-series object. This name can differ from the time-series variable name.
ts = timeseries(data,time) creates the time-series object using the specified data and time.
ts = timeseries(data,time,quality) specifies quality in terms of codes defined by QualityInfo.Code.
ts = timeseries(data,Name,Value) uses one or more Name, Value pair arguments.
ts = timeseries(data,time,Name,Value) creates the time-series object using the specified (data,time), time, and Name, Value pair arguments.
ts = timeseries(data,time,quality,Name,Value) uses the specified quality.
data |
The time-series data, which can be an array of samples |
tsname |
Time-series name specified as a string Default: ' ' |
time |
The time vector. When time values are date strings, you must specify Time as a cell array of date strings. When the time vector contains duplicate values:
Interpolating time-series data using methods like resample and synchronize can produce different results depending on whether the input timeseries contains duplicate times. Default: A time vector that ranges from 0 to N-1 with a 1-second interval, where N is the number of samples. |
quality |
An integer vector with values-128 to 127 that specifies the quality in terms of codes defined by QualityInfo.Code When Quality is a vector:
When Quality is an array:
|
Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
Data |
Time-series data, where each data sample corresponds to a specific time The data can be a scalar, a vector, or a multidimensional array. Either the first or last dimension of the data must align with Time. By default, NaNs represent missing or unspecified data. Set the TreatNaNasMissing property to determine how missing data is treated in calculations. Attributes:
| ||||
DataInfo |
Contains fields for storing contextual information about Data:
| ||||
Events |
An array of tsdata.event objects that stores event information for this timeseries object. You add events by using the addevent method. Fields of the tsdata.event object include the following:
| ||||
IsTimeFirst |
Logical value (true or false) specifies whether the first or last dimension of the Data array is aligned with the time vector. You can set this property when the Data array is square and it is ambiguous which dimension is aligned with time. By default, the first Data dimension that matches the length of the time vector is aligned with the time vector. When you set this property to:
Attributes:
| ||||
Length |
Length of the time vector in the timeseries object Attributes:
| ||||
Name |
The timeseries object name entered as a string. This name can differ from the name of the timeseries variable in the MATLAB workspace. | ||||
Quality |
An integer vector or array containing values -128 to 127 that specify the quality in terms of codes defined by QualityInfo.Code. When Quality is a vector, it must have the same length as the time vector. In this case, each Quality value applies to a corresponding data sample. When Quality is an array, it must have the same size as the data array. In this case, each Quality value applies to the corresponding value of the data array. Attributes:
| ||||
QualityInfo |
Provides a lookup table that converts numerical Quality codes to readable descriptions. QualityInfo fields include the following:
Lengths of Code and Description must match. | ||||
Time |
Array of time values. When TimeInfo.StartDate is empty, the numerical Time values are measured relative to 0 in specified units. When TimeInfo.StartDate is defined, the time values are date strings measured relative to the StartDate in specified units. The length of Time must be the same as either the first or the last dimension of Data. Attributes:
| ||||
TimeInfo |
Uses the following fields for storing contextual information about Time:
| ||||
TreatNaNasMissing |
Logical value that specifies how to treat NaN values in Data:
| ||||
UserData |
Generic field for data of any class that you want to add to the object. Default: [] |
Methods to Query and Set Object Properties and Plot the Data
Methods to Calculate Descriptive Statistics for a timeseries Object
Query timeseries object property values. | |
Return the size of each data sample in a timeseries object. | |
Return data quality descriptions based on the Quality property values assigned to a timeseries object. | |
Plot the timeseries object. | |
Set timeseries property values. |
Add a data sample to a timeseries object. | |
Concatenate timeseries objects in the time dimension. | |
Transpose a timeseries object. | |
Delete a sample from a timeseries object. | |
Subtract the mean or best-fit line and remove all NaNs from time-series data. | |
Shape frequency content of time-series data using a 1-D digital filter. | |
Extract a date-string time vector from a timeseries object into a cell array. | |
Extract a subset of data samples from an existing timeseries object into an array using a subscripted indexed array. | |
Extract a subset of data samples from an existing timeseries object into a new timeseries object using a subscript indexed array. | |
Get the interpolation method for a timeseries object. | |
Extract data samples from an existing timeseries object into a new timeseries object based on specified start and end time values. | |
Apply an ideal pass or notch (noncausal) filter to a timeseries object. | |
Select or interpolate data in a timeseries object using a new time vector. | |
Set the time values in the time vector as date strings. | |
Set interpolation method for a timeseries object. | |
Assign uniform time vector to timeseries object. | |
Synchronize and resample two timeseries objects using a common time vector. | |
Transpose a timeseries object. |
To construct an event object, use the constructor tsdata.event. For an example of defining events for a time-series object, see Defining Events.
Add one or more events to a timeseries object. | |
Delete one or more events from a timeseries object. | |
Create a new timeseries object by extracting the samples from an existing time series that occur after or at a specified event. | |
Create a new timeseries object by extracting the samples that occur after a specified event from an existing time series. | |
Create a new timeseries object by extracting the samples that occur at the same time as a specified event from an existing time series. | |
Create a new timeseries object by extracting the samples that occur before or at a specified event from an existing time series. | |
Create a new timeseries object by extracting the samples that occur before a specified event from an existing time series. | |
Create a new timeseries object by extracting the samples that occur between two specified events from an existing time series. |
+ | Addition of the corresponding data values of timeseries objects. |
- | Subtraction of the corresponding data values of timeseries objects. |
.* | Element-by-element multiplication of timeseries data. |
* | Matrix-multiply timeseries data. |
./ | Right element-by-element division of timeseries data. |
/ | Right matrix division of timeseries data. |
.\ | Element-by-element left-array divide of timeseries data. |
\ | Left matrix division of timeseries data. |
Return the interquartile range of timeseries data. | |
Return the maximum value of timeseries data. | |
Return the mean of timeseries data. | |
Return the median of timeseries data. | |
Return the minimum of timeseries data. | |
Return the standard deviation of timeseries data. | |
Return the sum of timeseries data. | |
Return the variance of timeseries data. |
The time-series object, called timeseries, is a MATLAB variable that contains time-indexed data and properties in a single, coherent structure. For example, in addition to data and time values, you can also use the time-series object to store events, descriptive information about data and time, data quality, and the interpolation method.
A time-series data sample consists of one or more values recorded at a specific time. The number of data samples in a time series is the same as the length of the time vector.
For example, suppose that ts.data has the size 3-by-4-by-5 and the time vector has the length 5. Then, the number of samples is 5 and the total number of data values is 3 x 4 x 5 = 60.
A time vector of a timeseries object can be either numerical (double) values or valid MATLAB date strings.
When the timeseries TimeInfo.StartDate property is empty, the numerical time values are measured relative to 0 (or another numerical value) in specified units. In this case, the time vector is described as relative (that is, it contains time values that are not associated with a specific start date).
When TimeInfo.StartDate is nonempty, the time values are date strings measured relative to StartDate in specified units. In this case, the time vector is described as absolute (that is, it contains time values that are associated with a specific calendar date).
MATLAB supports the following date-string formats for time-series applications.
| Date-String Format | Usage Example |
|---|---|
| dd-mmm-yyyy HH:MM:SS | 01-Mar-2000 15:45:17 |
| dd-mmm-yyyy | 01-Mar-2000 |
| mm/dd/yy | 03/01/00 |
| mm/dd | 03/01 |
| HH:MM:SS | 15:45:17 |
| HH:MM:SS PM | 3:45:17 PM |
| HH:MM | 15:45 |
| HH:MM PM | 3:45 PM |
| mmm.dd,yyyy HH:MM:SS | Mar.01,2000 15:45:17 |
| mmm.dd,yyyy | Mar.01,2000 |
| mm/dd/yyyy | 03/01/2000 |
Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB Programming Fundamentals documentation.
Create a timeseries object called 'LaunchData' that contains four data sets, each stored as a column of length 5 and using the default time vector:
b = timeseries(rand(5, 4),'Name','LaunchData')
Create a timeseries object containing a single data set of length 5 and a time vector starting at 1 and ending at 5:
b = timeseries(rand(5,1),[1 2 3 4 5])
Create a timeseries object called 'FinancialData' containing five data points at a single time point:
b = timeseries(rand(1,5),1,'Name','FinancialData')
Use the Time Series Tools.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |