MATLAB 7 Data Analysis

3y ago
39 Views
3 Downloads
1.80 MB
200 Pages
Last View : 5d ago
Last Download : 3m ago
Upload by : Isobel Thacker
Transcription

MATLAB 7Data Analysis

How to Contact The MathWorksWebNewsgroupwww.mathworks.com/contact TS.html Technical service@mathworks.cominfo@mathworks.comProduct enhancement suggestionsBug reportsDocumentation error reportsOrder status, license renewals, passcodesSales, pricing, and general information508-647-7000 (Phone)508-647-7001 (Fax)The MathWorks, Inc.3 Apple Hill DriveNatick, MA 01760-2098For contact information about worldwide offices, see the MathWorks Web site.MATLAB Data Analysis COPYRIGHT 2005–2007 by The MathWorks, Inc.The software described in this document is furnished under a license agreement. The software may be usedor copied only under the terms of the license agreement. No part of this manual may be photocopied orreproduced in any form without prior written consent from The MathWorks, Inc.FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentationby, for, or through the federal government of the United States. By accepting delivery of the Program orDocumentation, the government hereby agrees that this software or documentation qualifies as commercialcomputer software or commercial computer software documentation as such terms are used or definedin FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions ofthis Agreement and only those rights specified in this Agreement, shall pertain to and govern the use,modification, reproduction, release, performance, display, and disclosure of the Program and Documentationby the federal government (or other entity acquiring for or through the federal government) and shallsupersede any conflicting contractual terms or conditions. If this License fails to meet the government’sneeds or is inconsistent in any respect with federal procurement law, the government agrees to return theProgram and Documentation, unused, to The MathWorks, Inc.TrademarksMATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC TargetBoxare registered trademarks, and SimBiology, SimEvents, and SimHydraulics are trademarks ofThe MathWorks, Inc.Other product or brand names are trademarks or registered trademarks of their respectiveholders.PatentsThe MathWorks products are protected by one or more U.S. patents. Please seewww.mathworks.com/patents for more information.

Revision HistorySeptember 2005March 2006September 2006March 2007OnlineOnlineOnlineOnlineonlyonlyonlyonlyNew for MATLAB 7.1 (Release 14SP3)Revised for Version 7.2 (Release 2006a)Revised for Version 7.3 (Release 2006b)Revised for Version 7.4 (Release 2007a)

ContentsPreparing Data for Analysis1MATLAB for Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Calculations on Vectors and Matrices . . . . . . . . . . . . . . . . .MATLAB GUIs for Data Analysis . . . . . . . . . . . . . . . . . . . .Related Toolboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-31-31-41-41-5Importing and Exporting Data . . . . . . . . . . . . . . . . . . . . . .1-7Plotting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example — Loading and Plotting Data . . . . . . . . . . . . . . . .1-81-81-8Removing and Interpolating Missing Values . . . . . . . . .Representing Missing Data Values . . . . . . . . . . . . . . . . . . .Calculating with NaNs . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Removing NaNs from the Data . . . . . . . . . . . . . . . . . . . . . .Interpolating Missing Data . . . . . . . . . . . . . . . . . . . . . . . . .1-101-101-101-111-12Removing Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-13Filtering Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Filter Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example 1 — Moving Average Filter . . . . . . . . . . . . . . . . . .Example 2 — Discrete Filter . . . . . . . . . . . . . . . . . . . . . . . .1-151-151-161-17Detrending Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example — Removing Linear Trends from the Data . . . . .1-201-201-20.1-24Descriptive Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-25Finite Differencesv

Functions for Calculating Descriptive Statistics . . . . . . . . .Example — Using MATLAB Data Statistics . . . . . . . . . . . .1-251-28Linear Regression Analysis2Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Residuals and Goodness of Fit . . . . . . . . . . . . . . . . . . . . . . .When to Use the Curve Fitting Toolbox . . . . . . . . . . . . . . . .2-22-22-32-3Correlation Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Correlation Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-52-52-52-7Interactive Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Basic Fitting GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Preparing for Basic Fitting . . . . . . . . . . . . . . . . . . . . . . . . . .Opening the Basic Fitting GUI . . . . . . . . . . . . . . . . . . . . . .Example — Using the Basic Fitting GUI . . . . . . . . . . . . . .2-92-92-102-102-11Programmatic Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .MATLAB Functions for Polynomial Models . . . . . . . . . . . .Linear Model with Nonpolynomial Terms . . . . . . . . . . . . . .Multiple Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Example — Data Fitting Using MATLAB Functions . . . . .2-232-232-272-292-30Fourier Analysis3viContentsIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-3

Calculating Fourier Transforms . . . . . . . . . . . . . . . . . . . .Example — Calculating the FFT of a Column Vector . . . . .3-43-5Example — Using FFT to Calculate SunspotPeriodicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-7Magnitude and Phase of Transformed Data . . . . . . . . . .3-11FFT Length Versus Performance . . . . . . . . . . . . . . . . . . . .3-13Time Series Objects and Methods4Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-2Time Series Data Sample . . . . . . . . . . . . . . . . . . . . . . . . . . .4-3Example — Using Time Series Objects and Methods . .Creating Time Series Objects . . . . . . . . . . . . . . . . . . . . . . . .Viewing Time Series Objects . . . . . . . . . . . . . . . . . . . . . . . .Modifying Time Series Units and Interpolation Method . .Defining Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating Time Series Collection Objects . . . . . . . . . . . . . . .Resampling a Time Series Collection Object . . . . . . . . . . . .Adding a Data Sample to a Time Series CollectionObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Removing and Interpolating Missing Data . . . . . . . . . . . . .Removing a Time Series from a Time Series Collection . . .Changing a Numerical Time Vector to Date Strings . . . . . .Plotting Time Series Collection Members . . . . . . . . . . . . . .4-64-64-84-114-124-124-14Time Series Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . .Time Vector Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Time Series Constructor Syntax . . . . . . . . . . . . . . . . . . . . .Time Series Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-214-214-224-24Time Series Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-314-154-164-184-184-19vii

General Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Data and Time Manipulation Methods . . . . . . . . . . . . . . . .Event Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Arithmetic Operation Methods . . . . . . . . . . . . . . . . . . . . . . .Statistical Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-314-324-334-344-35Time Series Collection Constructor . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Time Series Collection Constructor Syntax . . . . . . . . . . . . .Time Series Collection Properties . . . . . . . . . . . . . . . . . . . .4-364-364-364-38Time Series Collection Methods . . . . . . . . . . . . . . . . . . . . .General Time Series Collection Methods . . . . . . . . . . . . . . .Data and Time Manipulation Methods . . . . . . . . . . . . . . . .4-404-404-40Time Series Tools5viiiContentsIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Opening Time Series Tools . . . . . . . . . . . . . . . . . . . . . . . . . .Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Time Series Tools Window . . . . . . . . . . . . . . . . . . . . . . . . . .Time Series Tools Workflow . . . . . . . . . . . . . . . . . . . . . . . . .Generating Reusable M-Code . . . . . . . . . . . . . . . . . . . . . . . .5-25-25-35-35-55-6Importing and Exporting Data . . . . . . . . . . . . . . . . . . . . . .Types of Data You Can Import . . . . . . . . . . . . . . . . . . . . . . .How to Import Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Changes to Data Representation During Import . . . . . . . .Importing Multivariate Data . . . . . . . . . . . . . . . . . . . . . . . .Importing Data with Missing Values . . . . . . . . . . . . . . . . . .Exporting Data from Time Series Tools . . . . . . . . . . . . . . . .5-85-85-85-105-115-125-13Plotting Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Types of Plots in Time Series Tools . . . . . . . . . . . . . . . . . . .Creating a Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Customizing Line and Marker Styles . . . . . . . . . . . . . . . . .Editing Plot Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . .Time Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-145-145-155-165-165-18

Spectral Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Correlation Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .XY Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-195-215-225-27Selecting Data for Analysis . . . . . . . . . . . . . . . . . . . . . . . . .Selecting Data Using Rules . . . . . . . . . . . . . . . . . . . . . . . . .Selecting Data Graphically . . . . . . . . . . . . . . . . . . . . . . . . . .Excluding Data from Analysis . . . . . . . . . . . . . . . . . . . . . . .5-295-295-305-31Editing Data, Time, Attributes, and Events . . . . . . . . . . .Displaying the Data Table . . . . . . . . . . . . . . . . . . . . . . . . . .Editing Data and Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Defining Data Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . .Assigning Quality Codes to Data . . . . . . . . . . . . . . . . . . . . .Defining Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-325-325-335-355-375-38Processing and Manipulating Time Series . . . . . . . . . . .5-42Example — Using MATLAB Time Series Tools . . . . . . . .Loading Data into the MATLAB Workspace . . . . . . . . . . . .Starting Time Series Tools . . . . . . . . . . . . . . . . . . . . . . . . . .Enabling M-Code Generation . . . . . . . . . . . . . . . . . . . . . . . .Importing Data into Time Series Tools . . . . . . . . . . . . . . . .Creating a Time Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Resampling Time Series . . . . . . . . . . . . . . . . . . . . . . . . . . . .Comparing Data on an XY Plot . . . . . . . . . . . . . . . . . . . . . .Viewing Generated M-Code . . . . . . . . . . . . . . . . . . . . . . . . .Exporting Time Series to the Workspace . . . . . . . . . . . . . . .5-435-435-435-435-445-475-525-545-565-58Indexix

xContents

1Preparing Data for AnalysisThe following sections summarize MATLAB data-analysis capabilities, andprovide information about preparing your data for analysis.MATLAB for Data Analysis (p. 1-3)Provides an overview of dataanalysis using MATLABImporting and Exporting Data(p. 1-7)Explains where to get informationabout importing and exporting dataPlotting Data (p. 1-8)Provides information aboutMATLAB plots, and includes anexample of loading data from a textfile and creating a time plotRemoving and Interpolating MissingValues (p. 1-10)Describes using NaNs to representmissing data, as well as removing orinterpolating these valuesRemoving Outliers (p. 1-13)Describes how to identify and removevalues that seem inconsistent withthe majority of the dataFiltering Data (p. 1-15)Describes how to smooth and shapedata using filtersDetrending Data (p. 1-20)Describes how to remove the meanor a best-fit line from the data

11-2Preparing Data for AnalysisFinite Differences (p. 1-24)Summarizes MATLAB functions forcomputing finite differencesDescriptive Statistics (p. 1-25)Summarizes MATLAB functions forcalculating descriptive statistics andprovides an example of using theData Statistics dialog box

MATLAB for Data AnalysisMATLAB for Data Analysis “Introduction” on page 1-3 “Calculations on Vectors and Matrices” on page 1-4 “MATLAB GUIs for Data Analysis” on page 1-4 “Related Toolboxes” on page 1-5IntroductionMATLAB provides functions and GUIs to perform a variety of commondata-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. Afterexamining the plot, you can determine which portions of the data to include inthe analysis. You can also use the plot to evaluate if your data contains anyfeatures that might distort or confuse the analysis results, and then processyour data to work only with the regions of interest.This chapter describes the common techniques you can use to ready your datafor analysis. When you work with empirical data, it is often necessary totreat 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 page1-13. Smoothing the data using a first-order filter, a transfer function, or an idealfilter. 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” onpage 1-24.After isolating the data of interest, you can proceed with the coredata-analysis tasks, which might include basic data fitting (see Chapter 2,“Linear Regression Analysis”) and Fourier analysis (see Chapter 3, “Fourier1-3

1Preparing Data for AnalysisAnalysis”). If your data analysis requires more advanced or specializedfunctionality, see “Related Toolboxes” on page 1-5 to learn about the toolboxesavailable from The MathWorks.If you are working with time series data, MATLAB provides the timeseriesand tscollection objects and methods that enable you to efficientlyrepresent and manipulate time series data. For more information aboutcreating and working with these objects, see Chapter 4, “Time Series Objectsand Methods”. Alternatively, you can use the MATLAB Time Series Toolsgraphical user interface (GUI) to import, plot, and analyze time series. Formore information, see Chapter 5, “Time Series Tools”.Calculations on Vectors and MatricesWhereas some MATLAB functions support only vector inputs, others acceptmatrices.When your data is a vector, the result is the same whether the vector has arowwise or columnwise orientation.However, when your data is a matrix, MATLAB performs calculationsindependently for each column. This means that when you pass a matrixas an argument to the function max, for example, the result is a row vectorcontaining maximum data values for each column in the matrix.Note When your data is a matrix where each row contains a data set, youmust transpose the matrix before proceeding with the data-analysis tasks tomake the data sets have a columnwise orientation. For example, to transposea real matrix A, use the syntax A'.MATLAB GUIs for Data AnalysisIn addition to the various MATLAB functions for performing data analysis,MATLAB provides four graphical user interfaces (GUIs) that facilitatecommon data-analysis tasks. The following table lists these GUIs and tellsyou how to get more information about each one.1-4

MATLAB for Data AnalysisMATLAB GUIs for Data AnalysisGUIDescriptionMore InformationMATLABFigurewindowFor plotting variables in theMATLAB workspace andediting plot propertiesMATLAB GraphicsdocumentationDataStatisticsdialog boxFor calculating and plottingdescriptive statistics“Example — Using MATLABData Statistics” on page 1-28BasicFittingdialog boxFor basic data fitting usingpolynomial and splinemodels, as well as plottingfitted data and residuals“Interactive Fitting” on page2-9Time SeriesToolsFor plotting andmanipulating time seriesdataChapter 5, “Time SeriesTools”Related ToolboxesThe following table summarizes the toolboxes that extend MATLABdata-analysis capabilities. For the latest information about these and otherMathWorks products, point your Web browser towww.mathworks.comToolboxes That Extend MATLAB Data AnalysisToolboxDescriptionBioinformatics ToolboxImport, analyze, and visualize genomic,proteomic, and microarray data.Curve Fitting ToolboxInteractively model one-dimensional data.Financial ToolboxAnalyze financial data and develop financialalgorithms.Image ProcessingToolboxPerform image processing, analysis, andalgorithm development.1-5

1Preparing Data for AnalysisToolboxes That Extend MATLAB Data Analysis (Continued)1-6ToolboxDescriptionModel-Based CalibrationToolboxCalibrate complex powertrain systems.Neural Network ToolboxDesign and simulate neural networks.Optimization ToolboxFit nonlinear models to data.Signal ProcessingToolboxPerform signal processing, analysis, andalgorithm development.Spline ToolboxCreate and manipulate spline approximationmodels of data.Statistics ToolboxAnalyze and model data, simulate systems, anddevelop statistical algorithms.System IdentificationToolboxCreate linear dynamic models from measuredinput-output data.Wavelet ToolboxAnalyze and synthesize signals and imagesusing wavelet techniques.

Importing and Exporting DataImporting and Exporting DataThe first step in analyzing data is to import it into MATLAB. The MATLABProgramming documentation provides detailed information about supporteddata formats and the functions for bringing data into MATLAB.The easiest way to import data into MATLAB is to use the MATLAB ImportWizard, as described in the MATLAB Programming documentation. With theImport 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

The following sections summarize MATLAB data-analysis capabilities, and provide information about preparing your data for analysis. MATLAB for Data Analysis (p. 1-3) Provides an overview of data analysis using MATLAB Importing and Exporting Data (p. 1-7) Explainswheretogetinformation about importing and exporting data

Related Documents:

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

Lecture 14: MATLAB I “Official” Supported Version in CS4: MATLAB 2018a How to start using MATLAB: CS Dept. Machines - run ‘cs4_matlab’ Total Academic Handout (TAH) Local Install - software.brown.edu MATLAB Online (currently 2019a) - matlab.mathworks.com Navigating the Workspace (command window, variables, etc.) Data types in MATLAB (everything is a 64-bit .

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

Compiler MATLAB Production Server Standalone Application MATLAB Compiler SDK Apps Files Custom Toolbox Python With MATLAB Users With People Who Do Not Have MATLAB.lib/.dll .exe . Pricing Risk Analytics Portfolio Optimization MATLAB Production Server MATLAB CompilerSDK Web Application