31-10-2016, 12:15 PM
1462388205-dataanalysismatlab.pdf (Size: 1.8 MB / Downloads: 62)
Introduction
MATLAB provides functions and GUIs to perform a variety of common
data-analysis tasks, such as plotting data, computing descriptive statistics,
and performing linear correlation analysis, data fitting, and Fourier analysis.
Typically, the first step to any data analysis is to plot the data. After
examining the plot, you can determine which portions of the data to include in
the analysis. You can also use the plot to evaluate if your data contains any
features that might distort or confuse the analysis results, and then process
your data to work only with the regions of interest.
This chapter describes the common techniques you can use to ready your data
for analysis. When you work with empirical data, it is often necessary to
treat it by doing the following:
• Removing or interpolating missing values. For more information, see
“Removing and Interpolating Missing Values” on page 1-10.
• Removing outliers. For more information, see “Removing Outliers” on page
1-13.
• Smoothing the data using a first-order filter, a transfer function, or an ideal
filter. For more information, see “Filtering Data” on page 1-15.
• Removing the mean or a linear trend (detrending). For more information,
see “Detrending Data” on page 1-20.
• Differencing the data. For more information, see “Finite Differences” on
page 1-24.
After isolating the data of interest, you can proceed with the core
data-analysis tasks, which might include basic data fitting (see Chapter 2,
“Linear Regression Analysis”) and Fourier analysis (see Chapter 3, “Fourier
Analysis”). If your data analysis requires more advanced or specialized
functionality, see “Related Toolboxes” on page 1-5 to learn about the toolboxes
available from The MathWorks.
If you are working with time series data, MATLAB provides the timeseries
and tscollection objects and methods that enable you to efficiently
represent and manipulate time series data. For more information about
creating and working with these objects, see Chapter 4, “Time Series Objects
and Methods”. Alternatively, you can use the MATLAB Time Series Tools
graphical user interface (GUI) to import, plot, and analyze time series. For
more information, see Chapter 5, “Time Series Tools”.
Calculations on Vectors and Matrices
Whereas some MATLAB functions support only vector inputs, others accept
matrices.
When your data is a vector, the result is the same whether the vector has a
rowwise or columnwise orientation.
However, when your data is a matrix, MATLAB performs calculations
independently for each column. This means that when you pass a matrix
as an argument to the function max, for example, the result is a row vector
containing maximum data values for each column in the matrix.
Importing and Exporting Data
The first step in analyzing data is to import it into MATLAB. The MATLAB
Programming documentation provides detailed information about supported
data formats and the functions for bringing data into MATLAB.
The easiest way to import data into MATLAB is to use the MATLAB Import
Wizard, as described in the MATLAB Programming documentation. With the
Import Wizard, you can import the following types of data sources:
• Text files, such as .txt and .dat
• MAT-files
• Spreadsheet files, such as .xls
• Graphics files, such as .gif and .jpg
• Audio and video files, such as .avi and .wav
The MATLAB Import Wizard processes the data source and recognizes data
delimiters, as well as row or column headers, to facilitate the process of data
selection.
After you finish analyzing your data, you might have created new variables.
You can export these variables to a variety of file formats. For more
information about exporting data from the MATLAB workspace, see the
MATLAB Programming documentation.
When working with time series data, it is easiest to use the Time Series Tools
GUI to import the data and create timeseries objects. The Import Wizard in
Time Series Tools also makes it easy to import or define a time vector for your
data. For more information, see “Importing and Exporting Data” on page 5-8.
Plotting Data
• “Introduction” on page 1-8
• “Example — Loading and Plotting Data” on page 1-8
Introduction
After you import data into MATLAB, it is a good idea to plot the data so that
you can explore its features. An exploratory plot of your data enables you
to identify discontinuities and potential outliers, as well as the regions of
interest.
The MATLAB Graphics documentation fully describes the MATLAB figure
window, which displays the plot. It also discusses the various plot tools that
are available in MATLAB to help you annotate and edit plot properties.
If you are working with time series data, see Chapter 5, “Time Series Tools”,
for detailed information about working with time series plots.
Example — Loading and Plotting Data
In this example, you perform the following tasks on the data in a
space-delimited text file:
• “Loading the Data” on page 1-8
• “Plotting the Data” on page 1-9
This example uses sample data in count.dat that consists of three sets
of hourly traffic counts, recorded at three different town intersections over
a 24-hour period. Each data column in the file represents data for one
intersection.
Loading the Data
Import data into MATLAB using the load function:
load count.dat
Loading this data creates a 24-by-3 matrix called count in the MATLAB
workspace.