Time Series Tools

Introduction

Opening Time Series Tools

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.

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:

Syntax for Loading Data from the MATLAB® Workspace

MATLAB Object

Syntax

Description

timeseries

tstool(tsname)

tsname is the name of a timeseries object.

tscollection

tstool(tscname)

tscname is the name of a tscollection object.

Simulink logged-signal data

tstool(sldata)

sldata is the name of a signal logged in a Simulink model.

Getting Help

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.

Time Series Tools Window

The Time Series Tools window consists of the following three areas:

The following figure shows the three main areas of the Time Series Tools GUI:

Time Series Tools Workflow

When you analyze data using Time Series Tools, your workflow might include the following tasks:

  1. Import data from an Microsoft® Excel® workbook, MAT-file, or MATLAB workspace.

    For more information, see Importing and Exporting Data.

  2. Create a time plot to gain insight into the data features.

    For more information, see Creating a Plot.

  3. Select data subset for analysis.

    For more information, see Selecting Data Using Rules.

  4. Edit the data by

  5. Process the data by

    For more information, see Processing and Manipulating Time Series.

  6. Generating correlation plots, spectral plots, histograms, and XY plots.

    For more information, see Plotting Time Series.

  7. Exporting data from Time Series Tools to the MATLAB workspace or to a file.

    For more information, see Exporting Data from Time Series Tools.

Generating Reusable M-Code

You can enable automatic generation of reusable M-code while you perform operations that modify data in Time Series Tools. To do this, select File > Record M-Code in the Time Series Tools window.

If you are new to programming with MATLAB timeseries methods, you can use the generated M-code to get syntax examples. For more information about programming with MATLAB timeseries objects, see Time Series Objects.

For an example of automatically generating and viewing M-code, see Example: Time Series Tools.

Importing and Exporting Data

Types of Data You Can Import

You can import data into Time Series Tools from

How to Import Data

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.

Simulink logged signal

Select File > Import from Workspace > Simulink Data Logs.

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.

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:

  1. Right-click the text label of a field for which you want to get help.

  2. Select What's This from the shortcut menu.

Changes to Data Representation During Import

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:

Importing Multivariate Data

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:

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.

  1. 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.

  2. After importing the data, select the Time Series node in the tree and export these time series to the MATLAB workspace.

  3. 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.

  4. In Time Series Tools, select File > Import from Workspace > Time Series Objects or Collections and import the collection from the MATLAB workspace.

Importing Data with Missing Values

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:

  1. Select a time series or a collection in the Time Series Session tree containing missing values.

  2. Select Data > Interpolate or Data > Remove Missing Data, depending on the operation you want to perform. This opens the Process Data dialog box.

  3. Click Help to access context-sensitive help on specific options in the dialog box.

Exporting Data from Time Series Tools

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:

Plotting Time Series

Types of Plots in Time Series Tools

You can generate the following types of plots in Time Series Tools.

Plot TypeDescription
Time PlotPlots data as a function of time to help you see important features, such as outliers, discontinuities, trends, and periodicities.
HistogramPlots the number of data values that occur in specified data ranges, called bins.
Spectral PlotShows data periodicities by plotting the estimated power spectral density as a function of frequency.
Correlation PlotShows the autocorrelation of a time series or cross-correlation between two time series.
XY PlotShows 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.

Creating a Plot

You can create a plot in Time Series Tools is by dragging and dropping a Time Series data node in the Time Series Session tree onto a Views node.

The following figure shows an example of how to create a spectral plot by dragging the onboard 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.

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.

Customizing Line and Marker Styles

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.

Editing Plot Appearance

After you create a plot, you can modify the plot appearance using the Property Editor as follows:

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:

  1. Select the plot in the Time Series Session tree.

  2. In Time Series Tools, click the Edit Plot button. This displays the plot window on top with the Property Editor below the plot.

  3. In the Property Editor, click Help to get information about options and settings.

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.

Time Plots

By plotting data as a function of time, you can quickly gain insight into the following data features:

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

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

ButtonDescription

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.

Spectral Plots

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

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:

  1. In the Spectral Plot window, click the Select Frequency Interval(s) button in the toolbar.

  2. Click and drag on the plot to select a frequency interval. The selected interval appears in a different color.

  3. Decide if you want to select another frequency interval.

  4. Right-click a selected region on the plot and select one of the following from the shortcut menu:

Histograms

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.

After you create the plot, you can use the Property Editor to

In the Property Editor, click Help to get information about options and settings.

Selecting Data.  

  1. In the Histogram window, click the Select Y Range Interval button in the toolbar.

  2. Click and drag a rectangular region on the plot to select a data interval. The selected interval appears in a different color.

  3. Decide if you want to select another data range.

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.

Correlation Plots

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:

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.

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.

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 ValueMeaning

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.

XY Plots

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

Selecting Data for Analysis

Selecting Data Using Rules

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:

Selecting Data Graphically

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:

Selecting Data in a Rectangular Region.  

  1. In the Time Plot window, click the Select Data button in the toolbar.

  2. 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.

  3. Decide if you want to select another region.

Selecting Data in a Time Interval.  

  1. In the Time Plot window, click the Select Time Interval(s) button in the toolbar.

  2. 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.

  3. Decide if you want to select another time interval.

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.

Editing Data, Time, Attributes, and Events

Displaying the Data Table

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 intersection1:1 column contains the corresponding data values in the first column and only data column of intersection1.

If intersection1 had multiple data columns, they would appear in the table and numbered as intersection1:2, intersection1:3, and so on. The data column headers are also used as plot labels to distinguish time series in plots. For more information about creating plots, see Plotting Time Series.

Editing Data and Time

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.

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.

Defining Data Attributes

The following attributes are defined for time series:

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:

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.

  1. In the Define Data Attributes dialog box, click the Quality Codes tab.

  2. Click the Add Code button. This adds an empty row in the Quality Codes table.

  3. Click the empty cell in the Code column and type an integer from 0 to 127.

  4. Press the Tab key. This highlights the cell in the Description. Type one or two words that briefly describe the numerical code, such as Validated.

  5. 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.

Assigning Quality Codes to Data

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.

Defining Events

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:

  1. Make sure that the Show event table check box is selected. This check box is located below the data table:

  2. Click the Add event button below the event table. This opens the Define New Event dialog box.

  3. In the Name field, enter the name of the event, such as AMCommute.

  4. 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 Time Vector Format.

  5. 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

Processing and Manipulating Time Series

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.

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.

Example: Time Series Tools

Loading Data into the MATLAB® Workspace

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.

Starting Time Series Tools

To start Time Series Tools, type

tstool

This opens the Time Series Tools window. For more information about this GUI, see Time Series Tools.

Enabling M-Code Generation

In this portion of the example, you will enable automatic M-code generation in Time Series Tools to capture reusable M-code as a MATLAB function.

  1. In the Time Series Tools window, select File > Record M-Code. This opens the Record M-Code dialog box.

  2. Click the button and select the folder where you want to store the M-file.

  3. In the Log file name field, either select the name of a recently used file, or type a new name. The file name creates the function name you call in your M-code to reuse this function.

  4. To begin capturing M-code, click Record. The M-code is recorded until you stop recording, as described in Viewing Generated M-Code.

Importing Data into Time Series Tools

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.

  1. In the Time Series Tools window, select File > Import from Workspace > Array Data. This opens the Import Wizard.

  2. In the Import from list, select MATLAB workspace and click Next.

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

  4. 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.

  5. Click Next.

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

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

Creating a Time Plot

To explore the data, you can create a time plot of the three time series in the Time Series Tools window.

  1. 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.

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

  3. 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 press Enter.

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

  4. 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.

  5. In the Line Styles dialog box, click Line Style to distinguish the time series, shown as follows.

    The plot now looks like this.

Resampling Time Series

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.

  1. 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.

  2. In the Define Time Series area, select only intersection1 and clear the rest.

  3. In the Specify New Time Vector area, click Uniform time vector with time interval and specify the time interval as 2 hours. Click OK.

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.

  1. 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.

  2. In the Define Time Series area, select only intersection2 and clear the rest.

  3. In the Specify New Time Vector area, click Use time vector from time series and select 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.

Comparing Data on an XY Plot

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.

  1. 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.

  2. Drag and drop the intersection2 time series into the View2 node. This creates the following XY plot.

  3. To show the best-fit line on the XY plot, 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.

Viewing Generated M-Code

You can now view the M-code that Time Series Tools generated while you performed the previous steps in this example.

To view the M-file:

  1. In the Time Series Tools window, select File > Record M-Code to open the Record M-Code dialog box.

  2. Click Stop to open the M-file with the generated M-code in the MATLAB Editor.

Automatically Generated M-Code

You can reuse this M-code by calling the tstoollog function, which has the same name as this M-file. You specified the file name when you enabled M-code generation in this example, as described in Enabling M-Code Generation.

Examine the code of 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.

Exporting Time Series to the Workspace

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.

  1. Click the interesection1 node in the Time Series Session tree to select it.

  2. Select File > Export > To Workspace. The variable intersection1 is now listed in the MATLAB workspace.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS