| Contents | Index |
| On this page… |
|---|
Editing Data, Time, Attributes, and Events |
To open Time Series Tools, type the following at the MATLAB prompt:
tstool
You can also open Time Series Tools using the MATLAB Start button by selecting Start > MATLAB > Time Series Tools.
For a description of the Time Series Tools GUI, see Time Series Tools Window.
To learn how to import data into Time Series Tools, see Importing and Exporting Data.
You can also start Time Series Tools and simultaneously import the following kinds of objects from the MATLAB workspace:
timeseries
tscollection
Syntax for Loading Data from the MATLAB Workspace
MATLAB Object | Syntax | Description |
|---|---|---|
tstool(tsname) | tsname is the name of a timeseries object. | |
tscname is the name of a tscollection object. |
Time Series Tools provides extensive context-sensitive help directly from the GUI.
In the Time Series Tools window, the context-sensitive help
pane is available on the right to assist you with the primary tasks.
To toggle between displaying or hiding the help pane, click the
(Help)
button in the toolbar. You can resize the help pane by dragging the
vertical divider to the left or to the right.
Context-sensitive help is also available via the Help button in Time Series Tools dialog boxes.
The Time Series Tools window presents the following three areas, from left to right:
Time Series Session tree
Organizes time series data and plots (or Views).
Options and Settings pane
After you select a node in the tree, this pane displays options and settings pertaining to the node you selected in the tree.
Context-Sensitive Help pane
Provides information and instructions about entering the options
and settings currently shown in Time Series Tools. You can toggle
between displaying or hiding this help by clicking the
button
in the toolbar. You can change the width of the help pane by dragging
the vertical divider to the left or to the right.
To learn about other help available in Time Series Tools, see Getting Help.
The following figure shows the three main areas of the Time Series Tools GUI:

When you analyze data using Time Series Tools, your workflow might include the following tasks:
Import data from an Microsoft Excel workbook, MAT-file, or MATLAB workspace.
For more information, see Importing and Exporting Data.
Create a time plot to gain insight into the data features.
For more information, see Creating a Plot.
Select data subset for analysis.
For more information, see Selecting Data Using Rules.
Edit the data by
Identifying and removing outliers or "dead time" (see Selecting Data Using Rules.
Manually correcting errors (see Editing Data and Time).
Process the data by
Interpolating or removing missing values.
Detrending data by subtracting a mean value or a linear trend.
Filtering to smooth and shape the data.
Algebraically manipulating existing time series to create a new time series.
Resampling data using a specified time vector by selecting or interpolating values.
For more information, see Processing and Manipulating Time Series.
Generating correlation plots, spectral plots, histograms, and XY plots.
For more information, see Plotting Time Series.
Exporting data from Time Series Tools to the MATLAB workspace or to a file.
For more information, see Exporting Data from Time Series Tools.
You can enable automatic generation of reusable code while you perform operations that modify data in Time Series Tools. To do this, select File > Record Code in the Time Series Tools window.
If you are new to programming with MATLAB timeseries methods, you can use the generated code to study syntax examples. For more information about programming with MATLAB timeseries objects, see Time Series Objects.
For an example of automatically generating and viewing code, see Example: Time Series Tools.
Note The scope of the Record Code feature is restricted to recording actions on the time series data itself. It does not generate code to import data or reproduce time series plots. |
You can import data into Time Series Tools from
A Microsoft Excel workbook, a text file, or a MAT-file.
An array in the MATLAB workspace.
A timeseries or tscollection object in the MATLAB workspace.
For more information about creating these objects, see Time Series Objects.
This section includes the following topics:
Importing Time Series and Time Series Collection Objects. If you have already encapsulated time series data in a timeseries or tscollection object in the MATLAB workspace, you can open Time Series Tools and import the data in a single operation. Simply right-click the object name in the Workspace Browser and choose Open in Time Series Tools from the context menu.
Importing Data from External Files. Once you have opened Time Series Tools, use the following commands to import data from external files. Each command opens a dialog box. You can get detailed information about options by clicking Help.
Data Source | Import Command |
|---|---|
Microsoft Excel worksheet (.xls) | Select File > Create Time Series from File to open the Import Wizard. |
Text file (.csv, .txt, .dat) | Select File > Create Time Series from File to open the Import Wizard. |
MAT-file array (.mat) | Select File > Create Time Series from File to open the Import Wizard. |
MATLAB workspace array | Select File > Import from Workspace > Array Data to open the Import Wizard. |
timeseries or tscollection object in the MATLAB workspace | Select File > Import from Workspace > Time Series Objects or Collections. |
Using the Import Wizard. When in Time Series Tools, you import data from the MATLAB workspace or an external file using the Import Wizard. The Import Wizard lets you select the data to import when analyzing a portion of an Excel worksheet or specific columns or rows in a MATLAB array.
After you select the data, you can specify to import time values from a file or define a uniformly spaced time vector in the Import Wizard. For an example of importing data from an Excel worksheet, see Importing and Exporting Data.
Each time series you import is added as a data node to the Time Series Session tree.
Note The Import Wizard in Time Series Tools imports data as timeseries objects. This is different from the Import Wizard you access from the MATLAB Command Window, which imports data as MATLAB vectors and matrices. |
For instructions about working with the Import Wizard, click Help in the Import Wizard window. You can also get help on specific fields in the Wizard as follows:
Right-click the text label of a field for which you want to get help.
Select What's This from the shortcut menu.
When you import data into Time Series Tools, a copy of the data is imported without affecting the original data source.
The data copy is changed during import, as follows:
Row-wise data is transposed to become column-wise with the time vector in the first column.
Data with more than two dimensions is reshaped to two dimensions such that dimensions three and higher become additional columns. For example, a 2-by-3-by-5 data array becomes a 2-by-15 data array.
Non-double data, such as int, logical, and fixed-point, is converted to double.
Missing data values are replaced by NaNs.
A sparse matrix is converted to a full matrix.
Caution When you export data from Time Series Tools to a file or to the MATLAB workspace, please note that its representation might differ from what you imported into Time Series Tools. For more information about exporting data, see Exporting Data from Time Series Tools. |
When your data consists of several related variables measured at the same time, you might want to group this data so that you can plot variables together or perform calculations on all variables simultaneously.
There are two ways to represent multivariate data in Time Series Tools:
Create a time series collection with a common time vector, where each time series is a member of the collection.
Import a data array into a single timeseries object, where each time series is stored as a column.
Choosing How to Represent Multivariate Data. How you choose to represent your data depends on whether the variables have the same or different units.
When your data contains different measurements of the same quantity (same units), you can store all measurements as separate columns in a single time series. Plotting such a time series displays all columns on the same axes and distinguishes the data sets by line and marker styles. For more information, see Customizing Line and Marker Styles.
When your data contains different quantities, measured in different units, you might want to distinguish these quantities on plots and during analysis. In this case, we recommend that you store each quantity as a separate time series and then group them into a time series collection. For example, if you are working with stock-price data in a portfolio, you might represent each stock as a separate time series and group them in a collection. When you plot this collection, each member is plotted on separate axes. However, when you perform data-analysis operations on the collection, such as filtering or interpolation, these operations are applied to all time series in the collection simultaneously.
Creating a Time Series Collection. You can create a time series collection in the MATLAB Command Window, as described in Time Series Objects, and then import the collection into Time Series Tools. Alternatively, you can use the Import Wizard to facilitate creating the timeseries objects and then group them into a collection in the MATLAB Command Window.
The following procedure describes one way to create a time series collection using data from a file.
To import each variable in the Microsoft Excel worksheet or MATLAB array as a separate time series in Time Series Tools, select File > Import from Workspace > Array Data. This opens the Import Wizard.
After importing the data, select the Time Series node in the tree and export these time series to the MATLAB workspace.
In the MATLAB Command Window, combine individual time series into a time series collection object. For an example of creating a time series collection, see Creating Time Series Collection Objects.
In Time Series Tools, select File > Import from Workspace > Time Series Objects or Collections and import the collection from the MATLAB workspace.
When you import data from a Microsoft Excel worksheet into Time Series Tools that contains missing values, the missing data is automatically replaced with NaNs. NaNs are ignored in Time Series Tools calculations.
To remove or interpolate missing values:
Select a time series or a collection in the Time Series Session tree containing missing values.
Select Data > Interpolate or Data > Remove Missing Data, depending on the operation you want to perform. This opens the Process Data dialog box.
Click Help to access context-sensitive help on specific options in the dialog box.
Importing data into Time Series Tools creates a copy of the original data. After you finish analyzing the data in Time Series Tools, you must export it to a file or to the MATLAB workspace to make it available for other processing.
To export a time series or a collection, select the desired node in the Time Series Session tree. Then, do one of the following:
Export to a file (Microsoft Excel worksheet or MAT-file):
Select File > Export > To File.
When you export a time series collection, the individual time series are extracted into separate Microsoft Excel worksheets.
Export to the MATLAB workspace:
Select File > Export > To Workspace.
You can generate the following types of plots in Time Series Tools.
| Plot Type | Description |
|---|---|
| Time Plot | Plots data as a function of time to help you see important features, such as outliers, discontinuities, trends, and periodicities. |
| Histogram | Plots the number of data values that occur in specified data ranges, called bins. |
| Spectral Plot | Shows data periodicities by plotting the estimated power spectral density as a function of frequency. |
| Correlation Plot | Shows the autocorrelation of a time series or cross-correlation between two time series. |
| XY Plot | Shows the relationship between two time series by plotting the data values of one on the x-axis and the data values of the other on the y-axis. |
You can create a plot in the Time Series Tools GUI by dragging a Time Series data node from the Time Series Session tree and dropping it onto a Views folder node.
The following figure shows an example of how to create a spectral plot by dragging the intersection1 time series onto the Spectral Plots node:

This opens the spectral plot in the Time Series Plots window and adds a tree node under Spectral Plots. The Time Series Plots window is similar to the MATLAB Figure window but includes additional commands in the toolbar and the Tools menu.
Tip To change the default plot name, right-click the plot node and select Rename and enter the new name. |
Subplots. To create subplots in a single figure window, drag several time series onto the same plot node. If a time series contains several columns of data, all data columns are plotted on the same axes. See Editing Plot Appearance for information on interactively modifying the appearance of subplots.
XY and cross-correlation plots. These plots require two time series. To create these plots, drag one time series onto a plot node and then drag a second time series onto the same plot node.
When you plot several time series on the same axes, or a single timeseries object that contains multiple columns of data, you can specify how to visually distinguish between the different sets of data in the plot.
To distinguish data by color, type of marker, or line style, select Plot > Set Line Properties in the Time Series Tools window. This opens the Line Styles dialog box. Click Help to learn how to work with this dialog box.
For an example of setting line styles, see Creating a Plot.
After you create a plot, you can modify the plot appearance using the Property Editor as follows:
Change the range of the horizontal and vertical axes.
Show statistical annotations on the plot, such as the mean and standard deviation.
The kinds of statistical quantities you can display vary depending on the type of plot.
The following figure shows the location of the Property Editor relative to the plot window:

To display the Property Editor for any Time Series Tools plot:
Select the plot in the Time Series Session tree.
In Time Series Tools, click the Edit Plot button. This displays the plot window on top with the Property Editor below the plot.
In the Property Editor, click Help to get information about options and settings.
Note The Property Editor options change depending on the type of plot and the plot item you select, such as lines or plot legends. |
Subplots. You can change subplot indices interactively. To do so, click on a plotted line in a time series view and drag and drop it from one subplot to another. To create a new subplot, drag and drop the plotted line below the bottom axes.
By plotting data as a function of time, you can quickly gain insight into the following data features:
Outliers, or values that do not appear to be consistent with the rest of the data
Discontinuities
Trends
Periodicities
Time intervals containing the data of interest
These features, when considered in the context of the data, enable you to plan your analysis strategy. For more information about creating a time plot, see Creating a Plot.
After you create the plot, you can use the Property Editor to
Define Y-axis scale.
Display statistical annotations on the plot, such as mean, standard deviation, and median.
Define X-axis scale (or domain).
In the Property Editor, click Help to get information about options and settings.
The Time Plot window contains the following toolbar commands specific to working with time series data.
Time Plot Commands
| Button | Description |
|---|---|
|
| Select Data — Enables you to click and drag a rectangular region on the time plot to select the data inside the region. |
|
| Move Time Series — Enables you to click and drag a time series to translate a time series on the plot and recalculate the data and time values. When you translate a time series in time, its time vector is shifted by a constant offset. If you had associated any events with this time series, the events are not shifted with the time series. For more information about editing event times, see Defining Events. |
|
| Rescale Time Series — Rescales both axes of the time plot to the original view. |
|
| Select Interval — Enables you to click and drag to select data corresponding to one or more time intervals. You can select multiple disconnected intervals. |
You use a spectral plot (or periodogram) to determine the frequencies of the periodic variations in the data and to filter the data. For more information about creating a periodogram, see Creating a Plot.
The periodogram is the unbiased estimate of the power spectral density of a time series, calculated as the scaled absolute value of the (FFT)2 of the time series. The corresponding frequency vector is computed in cycles per unit time and has the same length as the power vector. The periodogram is scaled so that the variance equals the mean of the periodogram.
The periodogram is useful for picking out periodic components in the presence of noise; a peak in the periodogram indicates an important contribution to variance frequencies near the value that corresponds to the peak.
After you create the plot, you can use the Property Editor to
Define Y-axis scale.
Display the variance for a selected frequency range on the plot.
The periodogram is scaled so that the variance equals the mean of the periodogram.
Define frequency scale.
In the Property Editor, click Help to get information about options and settings.
Filtering the Data. You can use the spectral plot to apply an ideal pass or stop filter to the data.
You use the ideal notch (stop) filter when you want to attenuate the variations in the data for a specific frequency range. Alternatively, you use the ideal pass filter to allow only the variations in a specific frequency range. These filters are "ideal" in the sense that they are not realizable; an ideal filter is noncausal and the ends of the filter amplitude are perfectly flat in the frequency domain.
To apply an ideal filter:
In the Spectral Plot window, click the Select
Frequency Interval(s)
button in the toolbar.
Click and drag on the plot to select a frequency interval. The selected interval appears in a different color.
Decide if you want to select another frequency interval.
If yes, repeat step 2. The previously selected remains selected.
If no, go to step 4.
Right-click a selected region on the plot and select one of the following from the shortcut menu:
To allow only the variations in the selected frequency range, select Pass.
To remove the variations in the selected frequency range, select Notch.
The histogram plot shows the distribution of data by counting the number of data values within a specific range of values and displaying each range as a rectangular bin. The heights of the bins represent the numbers of values that fall within each range. For more information about creating a histogram, see Creating a Plot.
You can use a histogram plot to select data values that fall in a specific range to exclude or include them in your analysis. If you want to interpolate specific data values, you can select them in a histogram plot first, and then replace them with NaNs. For more information, see Removing and Interpolating Missing Data. Then, you can interpolate all values tagged as NaNs using the selected interpolation method. For more information about specifying an interpolation method, see Defining Data Attributes.
Note Time Series Tools generates a histogram plot of a time series by applying the MATLAB hist function. |
After you create the plot, you can use the Property Editor to
Define Y-axis scale.
Display statistical annotations on the plot, including the mean and the median.
Define data bins.
In the Property Editor, click Help to get information about options and settings.
In the Histogram window, click the Select Y
Range Interval
button
in the toolbar.
Click and drag a rectangular region on the plot to select a data interval. The selected interval appears in a different color.
Decide if you want to select another data range.
If yes, repeat step 2. The previously selected remains selected.
If no, you are done.
Removing or Replacing Data with NaNs. After you select the data, as described in Selecting Data for Analysis, you can delete it or replace it with NaNs. If you want to interpolate specific data values, you must replace the selected data with NaNs first.
To delete data, right-click the selected region and select Remove Selection from the shortcut menu.
To replace data with NaNs, right-click the selected region and select Replace with NaNs from the shortcut menu.
You can create autocorrelation plots (correlograms) and cross-correlation plots in Time Series Tools. A correlation plot shows correlation coefficients on the vertical axis, and lag values on the horizontal axis.
A lag is defined as the number of time steps by which a time series is shifted relative to itself (when autocorrelated), or relative to the corresponding time values of another time series (when crosscorrelated). Notice that a lag is not a time shift (in specified time units). However, you can interpret a lag as a time shift when the time series is uniformly sampled (autocorrelation), or when both time series are uniformly sampled with the same time interval (cross-correlation).
This section includes the following topics:
Note If your data is sampled at irregular time intervals, resample it on a uniform time vector before creating correlation plots. This is because correlation analysis only considers the number of time steps between data values, and not the actual time elapsed between successive measurements. For more information about resampling time series, see Processing and Manipulating Time Series. |
Autocorrelation of a Time Series. The autocorrelation function is an important diagnostic tool for analyzing time series in the time domain. You use the autocorrelation plot, or correlogram, to better understand the evolution of a process through time by the probability of relationship between data values separated by a specific number of time steps.
The correlogram plots correlation coefficients on the vertical axis, and lag values on the horizontal axis. To learn more about correlation coefficients, see Correlation Coefficients.
To create a correlogram, drag and drop a time series into a Correlations node. Then explore the plot by editing the lag range in the Property Editor.
If a time series contains multiple data columns, your plot contains cross-correlations of the various data columns. For more information, see Cross-Correlation of Time Series.
Note A correlogram is not useful when the data contains a trend; data at all lags will appear to be correlated because a data value on one side of the mean tends to be followed by a large number of values on the same side of the mean. You must remove any trend in the data before you create a correlogram. For more information about accessing detrending functionality, see Processing and Manipulating Time Series. |
Cross-Correlation of Time Series. Cross-correlation is a measure of the degree of the linear relationship between two time series. A high correlation between time series at a specific lag might indicate a time delay in the system.
Note Before creating a cross-correlation plot, make sure that both time series have the same uniform time vector. |
To create a cross-correlation plot, successively drag and drop the first time series and the second time series into the same Correlations node in the Time Series Session tree. Then explore the plot by varying the lag range in the Property Editor.
A cross-correlation plot of two time series, where each contains a single column of data, shows the degree of linear relationship between the data values in the two time series at various lags. For example, the following figure shows a cross-correlation plot of two time series, intersection1 and intersection2. There is a high correlation when there is no lag in the data, as well as for lags of about -11 and 11.
Cross-Correlation of Two Time Series

A cross-correlation plot of two time series, where each contains multiple data columns, is displayed as a grid of subplots. The number of subplots equals the number of columns of data in the first time series multiplied by the number of columns of data in the second time series.
When you autocorrelate a time series with multiple data columns, the resulting plot also contains subplots. The diagonal of the subplot is the autocorrelation of a specific data column. The off-diagonal subplots are cross-correlation plots of the various columns. The subplot indices correspond to the indices of the data columns being correlated. For example, the figure below shows a correlation plot of the time series counts with three data columns.
Cross-Correlation of Multiple Data Columns in a Time Series

Interpreting Correlation Plots. The following table describes the degree of relationship between the data values at a given lag for various correlation values.
| Correlation Value | Meaning |
|---|---|
Close to 1 | There is a relationship between data values at a specific lag: an increase in one corresponds to an increase in the other. |
0 | The variations in the data show no relationships at this lag. |
Close to -1 | There is an anticorrelation between the data values at a specific lag: a decrease in one data value corresponds to an increase in the other data value. |
Cross-Correlation Algorithm. When computing the cross-correlation of two vector-valued time series x and y, Time Series Tools uses an algorithm that is functionally equivalent to calling the Signal Processing Toolbox xcorr function from with the 'biased' option, after the time series means have been removed. Unlike xcorr, however, the cross-correlation estimate in Time Series Tools also works for matrix-valued time series X and Y, where it computes the cross-correlation of X(:,i) against Y(:,j) for all combinations of columns i and j. Note that Time Series Tools do not actually use the xcorr code, but rather a simplified version which works under these restricted assumptions.
An XY plot plots the data values of one time series against the data values of another time series at corresponding times. Any relationship between the two time series is evident from a pattern on the plot. For example, when the points on the XY plot form a straight line, there is a linear relationship between the data values of the two time series plotted. The XY plot does not show any time information.
To create an XY plot, successively drag and drop the first time series and the second time series into the same XY Plots node in the Time Series Session tree.
When you are plotting two time series where each contains a single column of data, the XY plot includes a single set of axes. The pairs of data values from the same position in the column of data; that is, the third data point from one column is plotted against the third data point from the other column. For an example of generating such an XY plot, see Comparing Data on an XY Plot.
An XY plot of two time series, where each contains one or multiple data columns, is displayed as a grid of subplots. The number of subplots equals the number of columns of data in the first time series multiplied by the number of columns of data in the second time series. The subplot indices correspond to the indices of the data columns.
The following figure shows an XY plot, where the data values in time series count are plotted on the X-axis against the corresponding data values of intersection1 on the Y-axis. Because count contains three data columns and intersection1 contains one data column, the XY plot window shows three subplots.
XY Plot Where One Time Series Contains Three Data Columns

You can select data using logical expressions in the Select Data Using Rules dialog box, which you access from a time plot. For more information about creating a time plot, see Creating a Plot.
To open the Select Data Using Rules dialog box, right-click inside the time plot and choose Select Data from the shortcut menu. Click Help in the dialog box to get information about specific options.
You can define up to four kinds of data-selection conditions:
Bounds — Upper and lower bounds for time and data values
Outliers — Condition for detecting outliers, or data values that are outside a specified confidence level
MATLAB expression — A logical MATLAB expression that selects specific data values
Flatlines – Condition for detecting a specified number of successive data points with a constant value
Tip To learn how to exclude data from analysis based on your selection, see Excluding Data from Analysis. |
This section describes how to select data in a time plot by using the mouse. For more information on creating a time plot, see Creating a Plot.
You can select data using two modes:
Data mode — Enables you to select data values in a rectangular region on the time plot.
For more information, see Selecting Data in a Rectangular Region.
Time mode — Enables you to select data values in one or more time intervals on the time plot.
For more information, see Selecting Data in a Time Interval.
Tip To learn how you can select specific data values in a histogram plot, see Selecting Data for Analysis. |
Selecting Data in a Rectangular Region.
In the Time Plot window, click the Select Data
button in the toolbar.
Click and drag a rectangular region on the plot that encloses the data you want to select.
The data values are selected when you release the mouse button.
Decide if you want to select another region.
If yes, repeat step 2. This does not clear the previous selection.
If no, you can continue by excluding data from analysis (see Excluding Data from Analysis).
Selecting Data in a Time Interval.
In the Time Plot window, click the Select Time
Interval(s)
button
in the toolbar.
Click the start of a region that encloses the time interval where you want to select data, and then drag it. The selected time interval appears in a different color.
Decide if you want to select another time interval.
If yes, repeat step 2. This does not clear the previous selection.
If no, you can continue by excluding data from analysis (see Excluding Data from Analysis).
After you select the data, you can either exclude or keep the selected values. The following table summarizes how to do this.
Task | Operation |
|---|---|
Exclude selected data from analysis | Right-click the selected data in the time plot and select Remove Observations from the shortcut menu. When there are multiple data columns in a single time series, this removes the entire data sample at that time. |
Exclude unselected data from analysis | Right-click the selected data in the time plot and select Keep Observations from the shortcut menu. |
To display the time series in an editable table, select the time series node in the Time Series Session tree.
In the following figure, the time series intersection1 is selected in the tree and its data table is shown on the right. The Time column contains time values and the Data:1 column contains the corresponding data values in the first and only data column of intersection1.
If intersection1 had multiple data columns, they would appear in the table and numbered as Data:2, Data:3, and so on.

Note
To toggle between displaying and hiding the help pane in Time
Series Tools, click the context-sensitve
help button
|
After you display the time series data, as described in Displaying the Data Table, you can edit specific data and time values, define a uniform time vector, and add or remove data samples.
Edit Time or Data Values. To edit a specific time or data value, double-click that cell in the table and enter the new value. Press Enter.
Note When entering time values, you must use the current display format of your time vector. For more information, see the Definition section of the timeseries reference page. |
Define a Uniform Time Vector. To define a uniformly-increasing time vector, click Uniform Time Vector below the data table. This opens the Define Uniform Time Vector dialog box.
Here, you specify the start and end time of the time vector, the time units, and the display format. The time interval is calculated automatically by dividing the total time range by the number of data samples. You can get more instructions by clicking Help in the Define Uniform Time Vector dialog box.
When you are done specifying the time vector, the new time values replace the previous time values in the data table.
Add Data Samples. To insert a row in the data table, click any cell in a row and click the Add Row button. Enter the time and the corresponding data values.
Delete Data Samples. To delete a row in the data table, select one or more rows with the mouse and click the Delete Row(s) button.
The following attributes are defined for time series:
Units — Stored as metadata for each time series.
Interpolation method — Default method used to fill in missing data or to resample data on a new time vector.
Quality codes — Used to annotate the quality of each value in the data table.
Click the Attributes button below the data table to open the Define Data Attributes dialog box. For information about displaying the data table, see Displaying the Data Table.
Units and Interpolation Method. Data units are stored as metadata for the currently selected time series. If this time series contains multiple data columns, all data is assigned the same units.
In the Units & Interpolation tab, enter a string in the Data units field. For example, enter N/m^2.
The interpolation method you select here is used by default for this time series to fill in missing data or to resample the data on a new time vector.
In the Units & Interpolation tab, select one of the following Interpolation methods:
Linear — A 1-D interpolation method that implements the MATLAB function interp1 to fit a straight line between a pair of existing data points to calculate the missing value.
Zero-order hold — Calculates the missing value by setting it equal to the last available data value. In other words, this methods "holds" the last value constant until the next available measurement.

Quality Codes. You can define quality codes to annotate the quality of each value in the data table. Each quality attribute consists of a numerical code and a brief description. For information about assigning quality codes to specific data values, see Assigning Quality Codes to Data.
Tip To save time, first define the quality attribute that applies to most of your data values. It is automatically assigned to all data values. Then, define the attributes that occur less frequently and set them manually in the Quality column of the data table. |
In the Define Data Attributes dialog box, click the Quality Codes tab.
Click the Add Code button. This adds an empty row in the Quality Codes table.
Double-click the empty cell in the Code column and type an integer from 0 to 127.
Double-click the empty cell in the Description column and type one or two words that briefly describe the numerical code, such as Validated.
To add another quality code, repeat steps 2 to 4. Or click OK to close the dialog box. This also assigns the first quality code you defined to all data values in the table.
The following figure shows two quality codes: Validated and Not validated.

After you define quality codes, as described in Quality Codes, the quality code you defined first is automatically assigned to all data values in the data table. For information about displaying the data table, see Displaying the Data Table.
To assign a different quality code to a specific data value, click the corresponding cell in the Quality column and select a different value from the drop-down list.

Events are stored as metadata for each time series. Time series events mark the data at a specific time in the data table and on a plot. For information about displaying the data table, see Displaying the Data Table.
You can also use events as reference points when shifting time series in time. For more information about synchronizing time series, see Processing and Manipulating Time Series.
To define events for the selected time series:
Make sure that the Show event table check box is selected. This check box is located below the data table:
Click the Add event button below the event table. This opens the Define New Event dialog box.
In the Name field, enter the name of the event, such as AMCommute.
In the Time/Date field, enter or edit the time of the event in the appropriate display format. For information about time-vector formats, see the Definition section of the timeseries reference page.
Click OK.
The following figure shows two events in the event table: AMCommute and PMCommute. The data table also contains both events and AMCommute is shown at 6.0 hours.

Events are displayed as markers on time series plots. The following figure shows the AMCommute marker (at 6.0 hours) and PMCommute marker (at 18.0 hours) on a time plot.
Time Plot with Event Markers

The following table summarizes the operations you can perform on individual time series or time series collection. These commands are available from the Data menu in Time Series Tools after you select a time series or collection node in the Time Series Session tree.
Note If you are viewing a time plot, these operations are available by right-clicking inside the time plot and selecting a command from the shortcut menu. For more information about plotting data, see Plotting Time Series. |
Each command opens a dialog box where you can get detailed instructions by clicking the Help button.
Data Analysis Commands
Command | Description |
|---|---|
| Data > Remove Missing Data | Delete the times that contain missing data. |
| Data > Detrend | Subtract a constant or a linear trend from the data. |
| Data > Filter | Smooth and shape the time series data. |
| Data > Interpolate | Interpolate missing values. |
| Data > Resample | Select or interpolate data values using a specified time vector. |
| Data > Transform Algebraically | Create a new time series by algebraically manipulating existing time series. This command is available only when you select an individual time series in the tree. |
| Data > Descriptive Statistics | Get summary statistics for each time series. |
Type the following command at the MATLAB prompt to load the hourly traffic counts at three road intersections, collected over a 24-hour period:
load count.dat
This adds the variable count to the MATLAB workspace.
To start Time Series Tools, type
tstool
This opens the Time Series Tools window. For more information about this GUI, see Time Series Tools.
In this portion of the example, you enable automatic code generation in Time Series Tools to capture your workflow as a MATLAB function.
In the Time Series Tools window, select File > Record Code.
The Record Code dialog box opens.
Click the
button,
and then select the folder where you want to store the code file.
In the Log file path field, either select the path of a recently used file, or type a new path.
Leave the File Name field as-is.
This field specifies the function name you call to reuse this function. For this example, keep the default file name, tstoollog.m.
To begin capturing code, click Record. The code is captured until you stop recording, as described in Viewing Generated MATLAB Code.
Tip You can close this dialog box without interrupting the recording operation by clicking Close. To reopen the dialog box, select File > Record Code in the Time Series Tools window. |
Note The scope of the Record Code feature is restricted to recording actions on the time series data itself. It does not generate code to import data or reproduce time series plots. |
This portion of the example shows how to create three time series from the 24-by-3 count array you loaded into the MATLAB workspace.
Note To get help on a specific field in the Import Wizard, right-click the field label and select What's This from the shortcut menu. |
In the Time Series Tools window, select File > Import from Workspace > Array Data. This opens the Import Wizard.
In the Import from list, select MATLAB workspace and click Next.

In Step 2 of the Import Wizard, select the count variable. The Import Wizard infers from the data that it is arranged in columns.

In the Specify Time Vector area, select hours from the Units list. In the Start Time field, type 1 to start the time vector at 1 hour. The Import Wizard has already filled in the remaining options to define a uniformly spaced time vector with a length of 24 and an interval of 1.

Click Next.
In Step 3 of the Import Wizard, select Create several time series using: common name+number. In the Enter common name field, type intersection.

Click Finish. This adds three time series to the Time Series Session tree: intersection1, intersection2, and intersection3 (as shown below).

To explore the data, you can create a time plot of the three time series in the Time Series Tools window.
In the Time Series Session tree, drag and drop the intersection1 time series into the Time Plots node. This creates a time plot in a new window with the default name View1.
A dialog box asks if you want to open the Property Editor for the plot. The Property Editor is one of the MATLAB Plotting Tools which has been customized for working with time series plots.If you click No, the View1 plot opens in a figure window. If you click Yes, the Property Editor opens as a panel within the window, as shown in the following illustration.

In the Time Series Session tree, drag and drop the intersection2 and intersection3 time series into View1 to add them to the plot.

To display all three time series on the same axes, click the View1 node in the Time Series Tools window. Change the subplot indices for intersection2 and intersection3 to [1], and then press Enter.

This displays all time series on the same axes, as follows:

To change the appearance of the time series in the plot, go to the main Time Series Tools window and select Plot > Set Line Properties. This opens the Line Styles dialog box.
In the Line Styles dialog box, click Line Style to distinguish the time series, shown as follows.

The plot now looks like this.

You can select or interpolate time series data using a specified time vector. When the new time vector contains time values that are not present in the original time vector, the intermediate data values are calculated using the interpolation method you associated with this time series. Linear interpolation is used by default. For more information about specifying the interpolation method, see Defining Data Attributes.
This portion of the example shows
Resampling on a Uniform Time Vector. First, you resample the time series intersection1 to include values every 2 hours.
Right-click inside the time plot you created in Creating a Plot and select Resample Data from the shortcut menu. This opens the Resample Data dialog box.

In the Define Time Series area, select only intersection1 and clear the rest.
In the Specify New Time Vector area, click Uniform time vector with time interval and specify the time interval as 2 hours. Click OK.
Tip To verify that intersection1 is resampled, select it in the Time Series Session tree and examine the data table. It should have a time vector that starts at 1 hour and increases in increments of 2 hours. |
Resampling by Finding a Common Time Vector. In some cases, you might want one time series to have the same time vector as another time series on the overlapping region of time values. This is especially useful when you want a specific time series to inherit a nonuniformly spaced time vector.
In this example, you resample intersection2 on the same time vector as intersection1.
Right-click inside the time plot you created in Creating a Plot and select Resample Data from the shortcut menu. This opens the Resample Data dialog box.
In the Define Time Series area, select only intersection2 and clear the rest.
In the Specify New Time Vector area, click Use time vector from time series and select Time Series/intersection1 from the list. Click OK.
To verify that intersection2 is resampled, select it in the Time Series Session tree and examine the data table. It should have a time vector that starts at 1 hour and increases in increments of 2 hours.
The XY plot is useful for visually determining a relationship between the data values of time series at corresponding times. For example, when the points on an XY plot form a straight line, there is a linear relationship between the two time series.
In this portion of the example, you examine the relationship between the corresponding data values of intersection1 and intersection2 by using an XY plot.
In the Time Series Session tree, drag and drop the intersection1 time series into the XY Plots node. This creates a new plot node with the default name View2.
Drag and drop the intersection2 time series into the View2 node. This creates the following XY plot.

To show the best-fit line on the XY plot, use the Property Editor. If the property editor is not open, display it by selecting Property Editor from the figure Tools menu. Click the Define Statistical Annotations tab in the Property Editor and select the Best fit line check box. Then, click the line to display the line equation on the plot.

You can now view the code that Time Series Tools generated while you performed the previous steps in this example.
To view the code file:
In the Time Series Tools window, select File > Record Code.
In the Record Code dialog box, click Stop to open the file containing the generated code in the MATLAB Editor.
Automatically Generated Code

You can execute this generated code by calling the tstoollog function, also the name of this code file. You kept this default file name when you enabled code generation in this example, as described in Enabling MATLAB Code Generation.
Examine the tstoollog function to confirm that it takes two time series as input arguments and resamples them using a uniform time vector with the range 1 to 24 and intervals of 2.
Note The scope of the Record Code feature is restricted to recording actions on the time series data itself. It does not generate code to import data or reproduce time series plots. |
You can export individual time series, as well as time series collections, from Time Series Tools to the MATLAB workspace. You can also export time series to a Microsoft Excel worksheet or a MAT-file.
In this portion of the example, you will export the time series intersection1 as a variable to the MATLAB workspace. This time series differs from the original data you imported into Time Series Tools because it has been resampled, as described in Resampling Time Series.
Click the interesection1 node in the Time Series Session tree to select it.
Select File > Export > To Workspace. The variable intersection1 is now listed in the MATLAB workspace.
![]() | Time Series Objects | Examples | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |