Curso Básico de Matlab

Page 1

Table of Contents

MLBE912V1

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-1


Table of Contents

Objetivo El objetivo general del curso es dotar a los asistentes de la habilidad básica del uso de la herramienta MATLAB, como un software de computo técnico. Al final el curso, los asistentes podrán realizar las 3 tareas básicas del computo técnico: Obtener datos de diversos medios; Procesarlos matemáticamente y visualizarlos; Compartir los resultados a través de aplicaciones y reportes.

Principales Beneficios MATLAB es un software líder en el computo científico y técnico, pensado como una plataforma de computo al tiempo que es un poderoso lenguaje de programación de alto nivel. Su creación ha sido pensada en automatizar cálculos y realizar tareas matemáticas complejas de manera interactiva, estructurada y programática. por lo que su conocimiento básico deriva en una reducción de tiempo en la realización de tareas de análisis y visualización de datos, desarrollo de aplicaciones simples y publicación de resultados.

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-2


Table of Contents NOSOTROS Somos una empresa mexicana con más de 15 años de experiencia. Fundada en 1989 para satisfacer la creciente demanda del mercado especializado de Software Científico y Técnico para la Industria, las Ciencias, los Servicios y la Educación de México y Latinoamérica. Ofrecemos Cursos de MINITAB, MATLAB, MAPLE, entre otros productos. Nuestra consultoría consiste en el desarrollo de aplicaciones científicas y técnicas, integración de sistemas en las áreas de control, electrónica, mecánica, finanzas, instrumentación, medición, adquisición/ captura de datos en línea y análisis en tiempo real para control de procesos. Visitenos www.multion.com.mx Mayores informes (Cursos) Joel Cervantes MultiON Consulting, SA de CV!!!! Insurgentes Sur 1236-301 México, DF, 03200 MEXICO Tel.: (55) 5559-4050 ext. 119 Fax: (55) 5559-4048 Country Code: 52 Email: cursos@multion.com.mx

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-3


Table of Contents ! ! ! ! ! ! ! ! ! ! Š COPYRIGHT 2010-2012 by The MathWorks, Inc. ! This Training Course Notebook, along with other Training Course Examples and Exercises, shall at all times remain the intellectual property of The MathWorks, Inc. The MathWorks, Inc. reserves all rights in these materials. No part of these materials may be photocopied, reproduced in any form, or distributed without prior written consent from The MathWorks, Inc. ! The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. !

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-4


Table of Contents

Table of Contents 1.

Introduction

10.  Logic and Flow Control

2.

Working with the MATLAB® User Interface

11.

3.

Variables and Expressions

12.  Data Analysis

4.

Analysis and Visualization with Vectors

13.  Writing Functions

5.

Analysis and Visualization with Matrices

14.  Troubleshooting Code and Improving Performance

6.

Automating Commands with Scripts

15.  Data Types

7.

Working with Data Files

16.  Conclusion

8.

Working with Text and Dates

Appendices

9.

Multiple Vector Plots

© 2014 by MathWorks, Inc.

Matrix and Image Visualization

MATLAB Fundamentals

TOC-5


Table of Contents

Table of Contents 1. Introduction MathWorks™ at a Glance........................................................................................................................................................................................................ 1-2 Worldwide Offices................................................................................................................................................................................................................... 1-3 MathWorks™ Product Overview...........................................................................................................................................................................................

1-4

Diverse Users............................................................................................................................................................................................................................ 1-5 Computer Setup.......................................................................................................................................................................................................................

1-6

MATLAB®?...................................................................................................................................................................................

1-7

Course Learning Outcomes...................................................................................................................................................................................................

1-8

Course Outline.........................................................................................................................................................................................................................

1-9

What Can You Do with

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-6


Table of Contents

Table of Contents 2. Working with the MATLAB® User Interface Outline....................................................................................................................................................................................................................................... 2-2 Chapter 2 Learning Outcomes..............................................................................................................................................................................................

2-3

The MATLAB® Desktop.......................................................................................................................................................................................................

2-4

Customizing the Desktop....................................................................................................................................................................................................... 2-5 Course Example: Gas Price Data.......................................................................................................................................................................................... 2-6 Interactive Importing..............................................................................................................................................................................................................

2-7

Variables in the Base Workspace...........................................................................................................................................................................................

2-8

The Variable Editor.................................................................................................................................................................................................................

2-9

New Variables........................................................................................................................................................................................................................... 2-10 Saving and Loading Variables................................................................................................................................................................................................

2-11

Plotting the Data...................................................................................................................................................................................................................... 2-12 Plot Tools..................................................................................................................................................................................................................................

2-13

Multiple Plots...........................................................................................................................................................................................................................

2-14

Formatting the Plot.................................................................................................................................................................................................................

2-15

Data Statistics Tool.................................................................................................................................................................................................................. 2-16 Basic Fitting Tool..................................................................................................................................................................................................................... 2-17 Exporting to Another Application.......................................................................................................................................................................................

2-18

Shortcuts...................................................................................................................................................................................................................................

2-19

Summary.................................................................................................................................................................................................................................... 2-20 Chapter 2 Test Your Knowledge........................................................................................................................................................................................... 2-21 © 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-7


Table of Contents

Table of Contents 3. Variables and Expressions Outline....................................................................................................................................................................................................................................... 3-2 Chapter 3 Learning Outcomes..............................................................................................................................................................................................

3-3

MATLAB® Commands..........................................................................................................................................................................................................

3-4

Saving and Loading MAT-Files.............................................................................................................................................................................................

3-5

Assignment...............................................................................................................................................................................................................................

3-6

Creating Vectors....................................................................................................................................................................................................................... 3-7 Creating Matrices.....................................................................................................................................................................................................................

3-8

Matrix Creation Functions.....................................................................................................................................................................................................

3-9

Help and Documentation....................................................................................................................................................................................................... 3-10 Row, Column Indexing...........................................................................................................................................................................................................

3-11

Multiple Row, Column Indices..............................................................................................................................................................................................

3-12

Indexed Assignment................................................................................................................................................................................................................ 3-13 Concatenation..........................................................................................................................................................................................................................

3-14

Characters and Strings............................................................................................................................................................................................................. 3-15 Summary.................................................................................................................................................................................................................................... 3-16 Chapter 3 Test Your Knowledge........................................................................................................................................................................................... 3-17

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-8


Table of Contents

Table of Contents 4. Analysis and Visualization with Vectors Outline....................................................................................................................................................................................................................................... 4-2 Chapter 4 Learning Outcomes..............................................................................................................................................................................................

4-3

Statistical Functions................................................................................................................................................................................................................. 4-4 Array Operations.....................................................................................................................................................................................................................

4-5

Mathematical Operations.......................................................................................................................................................................................................

4-6

Plotting Vectors........................................................................................................................................................................................................................ 4-7 Plot Options.............................................................................................................................................................................................................................

4-8

Annotating Plots......................................................................................................................................................................................................................

4-9

Additional Vector Plot Types................................................................................................................................................................................................. 4-10 Summary.................................................................................................................................................................................................................................... 4-11 Chapter 4 Test Your Knowledge........................................................................................................................................................................................... 4-13

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-9


Table of Contents

Table of Contents 5. Analysis and Visualization with Matrices Outline....................................................................................................................................................................................................................................... 5-2 Chapter 5 Learning Outcomes..............................................................................................................................................................................................

5-3

Determining Size.....................................................................................................................................................................................................................

5-4

Matrix Operations.................................................................................................................................................................................................................... 5-5 Array Operations.....................................................................................................................................................................................................................

5-6

Mathematical Operations.......................................................................................................................................................................................................

5-7

Data in the MATLABÂŽ Environment.................................................................................................................................................................................. 5-8 Statistical Operations............................................................................................................................................................................................................... 5-9 Plotting Multiple Columns.....................................................................................................................................................................................................

5-10

Reshaping..................................................................................................................................................................................................................................

5-11

Linear Indexing........................................................................................................................................................................................................................

5-12

Multidimensional Arrays......................................................................................................................................................................................................... 5-13 Summary.................................................................................................................................................................................................................................... 5-14 Chapter 5 Test Your Knowledge........................................................................................................................................................................................... 5-15

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-10


Table of Contents

Table of Contents 6. Automating Commands with Scripts Outline....................................................................................................................................................................................................................................... 6-2 Chapter 6 Learning Outcomes..............................................................................................................................................................................................

6-3

Course Example: Modeling a Whale Call............................................................................................................................................................................

6-4

The Command History........................................................................................................................................................................................................... 6-5 The MATLAB® Editor........................................................................................................................................................................................................... 6-6 Script Files................................................................................................................................................................................................................................. 6-7 Running a Script....................................................................................................................................................................................................................... 6-8 Code Sections...........................................................................................................................................................................................................................

6-9

Publishing Code....................................................................................................................................................................................................................... 6-10 Summary.................................................................................................................................................................................................................................... 6-11 Chapter 6 Test Your Knowledge........................................................................................................................................................................................... 6-13

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-11


Table of Contents

Table of Contents 7. Working with Data Files Outline....................................................................................................................................................................................................................................... 7-2 Chapter 7 Learning Outcomes..............................................................................................................................................................................................

7-3

File Types and File Formats .................................................................................................................................................................................................. 7-4 Reading and Writing Fixed-Format Files.............................................................................................................................................................................

7-5

Interactively Importing Text Files and Spreadsheets........................................................................................................................................................

7-6

Generating File I/O Code...................................................................................................................................................................................................... 7-7 Exporting Spreadsheets..........................................................................................................................................................................................................

7-8

Low-Level File I/O.................................................................................................................................................................................................................

7-9

Summary.................................................................................................................................................................................................................................... 7-10 Chapter 7 Test Your Knowledge........................................................................................................................................................................................... 7-11

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-12


Table of Contents

Table of Contents 8. Working with Text and Dates Outline....................................................................................................................................................................................................................................... 8-2 Chapter 8 Learning Outcomes..............................................................................................................................................................................................

8-3

Course Example: Car Specifications..................................................................................................................................................................................... 8-4 Cell Arrays................................................................................................................................................................................................................................. 8-5 Cell Indexing............................................................................................................................................................................................................................. 8-6 Converting Array Types.......................................................................................................................................................................................................... 8-7 Converting Numbers and Strings.......................................................................................................................................................................................... 8-8 Course Example: Electricity Consumption.........................................................................................................................................................................

8-9

Working with Dates................................................................................................................................................................................................................. 8-10 Plotting with Dates.................................................................................................................................................................................................................. 8-11 Summary.................................................................................................................................................................................................................................... 8-12 Chapter 8 Test Your Knowledge........................................................................................................................................................................................... 8-13

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-13


Table of Contents

Table of Contents 9. Multiple Vector Plots Outline....................................................................................................................................................................................................................................... 9-2 Chapter 9 Learning Outcomes..............................................................................................................................................................................................

9-3

Graphics Structure................................................................................................................................................................................................................... 9-4 Multiple Figures.......................................................................................................................................................................................................................

9-5

Multiple Axes............................................................................................................................................................................................................................ 9-6 Multiple Plots...........................................................................................................................................................................................................................

9-7

Plotting Functions...................................................................................................................................................................................................................

9-8

Annotation Techniques........................................................................................................................................................................................................... 9-9 Using Color............................................................................................................................................................................................................................... 9-10 Customizing Plots.................................................................................................................................................................................................................... 9-11 Axis Control.............................................................................................................................................................................................................................

9-12

Summary.................................................................................................................................................................................................................................... 9-13 Chapter 9 Test Your Knowledge........................................................................................................................................................................................... 9-15

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-14


Table of Contents

Table of Contents 10. Logic and Flow Control Outline....................................................................................................................................................................................................................................... 10-2 Chapter 10 Learning Outcomes............................................................................................................................................................................................

10-3

Logical Operations and Variables.......................................................................................................................................................................................... 10-4 Logical Functions..................................................................................................................................................................................................................... 10-5 Finding and Counting.............................................................................................................................................................................................................

10-6

Logical Indexing....................................................................................................................................................................................................................... 10-7 Programming Constructs.......................................................................................................................................................................................................

10-8

User Interaction.......................................................................................................................................................................................................................

10-9

Flow Control............................................................................................................................................................................................................................

10-10

For-Loops.................................................................................................................................................................................................................................

10-11

While-Loops.............................................................................................................................................................................................................................

10-12

Summary.................................................................................................................................................................................................................................... 10-13 Chapter 10 Test Your Knowledge......................................................................................................................................................................................... 10-15

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-15


Table of Contents

Table of Contents 11. Matrix and Image Visualization Outline....................................................................................................................................................................................................................................... 11-2 Chapter 11 Learning Outcomes............................................................................................................................................................................................

11-3

Course Example: Ozone Measurements.............................................................................................................................................................................. 11-4 Making Grids............................................................................................................................................................................................................................ 11-5 Interpolating Scattered Data.................................................................................................................................................................................................. 11-6 Surface Plots.............................................................................................................................................................................................................................

11-7

Two-Dimensional Matrix Visualization................................................................................................................................................................................ 11-8 Indexed Images........................................................................................................................................................................................................................

11-9

Colormaps................................................................................................................................................................................................................................. 11-10 True Color Images................................................................................................................................................................................................................... 11-11 Summary.................................................................................................................................................................................................................................... 11-12 Chapter 11 Test Your Knowledge......................................................................................................................................................................................... 11-13

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-16


Table of Contents

Table of Contents 12. Data Analysis Outline....................................................................................................................................................................................................................................... 12-2 Chapter 12 Learning Outcomes............................................................................................................................................................................................

12-3

Course Example: Modeling Electricity Consumption.......................................................................................................................................................

12-4

Dealing with Missing Data.....................................................................................................................................................................................................

12-5

Piecewise Interpolation........................................................................................................................................................................................................... 12-6 Linear Correlation...................................................................................................................................................................................................................

12-7

Smoothing and Convolution ................................................................................................................................................................................................. 12-8 Polynomial Fitting.................................................................................................................................................................................................................... 12-9 Linear Regression Models......................................................................................................................................................................................................

12-10

Frequency Analysis..................................................................................................................................................................................................................

12-11

FFTs...........................................................................................................................................................................................................................................

12-12

Matrix Equations.....................................................................................................................................................................................................................

12-13

Slash and Backslash.................................................................................................................................................................................................................

12-14

Solving Linear Systems...........................................................................................................................................................................................................

12-15

Summary.................................................................................................................................................................................................................................... 12-16 Chapter 12 Test Your Knowledge......................................................................................................................................................................................... 12-17

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-17


Table of Contents

Table of Contents 13. Writing Functions Outline....................................................................................................................................................................................................................................... 13-2 Chapter 13 Learning Outcomes............................................................................................................................................................................................

13-3

Increasing Automation...........................................................................................................................................................................................................

13-4

Creating a Function................................................................................................................................................................................................................. 13-5 Calling a Function.................................................................................................................................................................................................................... 13-6 Workspaces............................................................................................................................................................................................................................... 13-7 Subfunctions............................................................................................................................................................................................................................. 13-8 Calling Precedence................................................................................................................................................................................................................... 13-9 The MATLAB® Path..............................................................................................................................................................................................................

13-10

Summary.................................................................................................................................................................................................................................... 13-11 Chapter 13 Test Your Knowledge......................................................................................................................................................................................... 13-13

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-18


Table of Contents

Table of Contents 14. Troubleshooting Code and Improving Performance Outline....................................................................................................................................................................................................................................... 14-2 Chapter 14 Learning Outcomes............................................................................................................................................................................................

14-3

Debugging................................................................................................................................................................................................................................. 14-4 Analyzing Code in the Editor................................................................................................................................................................................................

14-5

Using Breakpoints.................................................................................................................................................................................................................... 14-6 Examining Values....................................................................................................................................................................................................................

14-7

Ending Debugging..................................................................................................................................................................................................................

14-8

Code Performance................................................................................................................................................................................................................... 14-9 Preallocation of Memory........................................................................................................................................................................................................ 14-10 Vectorization............................................................................................................................................................................................................................. 14-11 Summary.................................................................................................................................................................................................................................... 14-12 Chapter 14 Test Your Knowledge......................................................................................................................................................................................... 14-13

Š 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-19


Table of Contents

Table of Contents 15. Data Types Outline....................................................................................................................................................................................................................................... 15-2 Chapter 15 Learning Outcomes............................................................................................................................................................................................

15-3

MATLAB® Data Types........................................................................................................................................................................................................... 15-4 Integer Arrays........................................................................................................................................................................................................................... 15-5 Nondouble Arithmetic............................................................................................................................................................................................................ 15-6 Structures..................................................................................................................................................................................................................................

15-7

Structure Arrays.......................................................................................................................................................................................................................

15-8

Indexing into Structure Arrays..............................................................................................................................................................................................

15-9

Function Handles..................................................................................................................................................................................................................... 15-10 Converting Types.....................................................................................................................................................................................................................

15-11

Summary.................................................................................................................................................................................................................................... 15-12 Chapter 15 Test Your Knowledge......................................................................................................................................................................................... 15-13

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-20


Table of Contents

Table of Contents Appendices MATLAB® Reference.............................................................................................................................................................................................................

A

Exercises.................................................................................................................................................................................................................................... B

© 2014 by MathWorks, Inc.

MATLAB Fundamentals

TOC-21


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.