MATLAB: A High-Level Technical Computing System, Study notes of Mathematics

Matlab is a high-level technical computing system with a development environment for managing code, files, and data. It offers interactive tools for exploratory data analysis, design, and problem-solving, as well as mathematical functions for linear algebra, statistics, fourier analysis, filtering, optimization, and numerical integration. The system also includes 2-d and 3-d graphics functions for visualizing data and tools for building custom graphical user interfaces.

Typology: Study notes

2010/2011

Uploaded on 04/15/2011

lilbryan91
lilbryan91 🇺🇸

2 documents

1 / 280

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MATLAB®7
Getting Started Guide
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download MATLAB: A High-Level Technical Computing System and more Study notes Mathematics in PDF only on Docsity!

MATLAB

Getting Started Guide

How to Contact MathWorks

www.mathworks.com Web comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical Support

[email protected] Product enhancement suggestions [email protected] Bug reports [email protected] Documentation error reports [email protected] Order status, license renewals, passcodes [email protected] Sales, pricing, and general information

508-647-7000 (Phone)

508-647-7001 (Fax)

The MathWorks, Inc.

3 Apple Hill Drive

Natick, MA 01760-

For contact information about worldwide offices, see the MathWorks Web site.

MATLAB ®^ Getting Started Guide

© COPYRIGHT 1984–2010 by 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. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this 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 Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.

Trademarks

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders.

Patents

MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information.

Contents

Getting Started

Introduction

Product Overview................................. 1-

Overview of the MATLAB Environment............... 1-

The MATLAB System.............................. 1-

Documentation.................................... 1-

Starting and Quitting the MATLAB Program......... 1-

Starting a MATLAB Session........................ 1-

Quitting the MATLAB Program...................... 1-

Matrices and Arrays

Matrices and Magic Squares........................ 2-

About Matrices................................... 2-

Entering Matrices................................. 2-

sum, transpose, and diag........................... 2-

Subscripts....................................... 2-

The Colon Operator................................ 2-

The magic Function................................ 2-

Expressions....................................... 2-

Variables........................................ 2-

Numbers........................................ 2-

Operators........................................ 2-

v

Programming

Desktop Tools and Development Environment

  • Functions 2-
  • Examples of Expressions 2-
  • Working with Matrices 2-
    • Generating Matrices 2-
    • The load Function 2-
    • Saving Code to a File 2-
    • Concatenation 2-
    • Deleting Rows and Columns 2-
  • More About Matrices and Arrays 2-
    • Linear Algebra 2-
    • Arrays 2-
    • Multivariate Data 2-
    • Scalar Expansion 2-
    • Logical Subscripting 2-
    • The find Function 2-
  • Controlling Command Window Input and Output 2-
    • The format Function 2-
    • Suppressing Output 2-
    • Entering Long Statements 2-
    • Command Line Editing 2-
  • Overview of Plotting 3-
    • Plotting Process 3-
    • Graph Components 3-
    • Figure Tools 3-
    • Arranging Graphs Within a Figure 3-
    • Choosing a Type of Graph to Plot 3-
  • Editing Plots 3-
    • Plot Edit Mode 3-
    • Using Functions to Edit Graphs 3-
  • Some Ways to Use Plotting Tools 3-
    • Plotting Two Variables with Plotting Tools 3-
    • Changing the Appearance of Lines and Markers 3-
    • Adding More Data to the Graph 3-
    • Changing the Type of Graph 3-
    • Modifying the Graph Data Source 3-
  • Preparing Graphs for Presentation 3-
    • Annotating Graphs for Presentation 3-
    • Printing the Graph 3-
    • Exporting the Graph 3-
  • Using Basic Plotting Functions 3-
    • Creating a Plot 3-
    • Plotting Multiple Data Sets in One Graph 3-
    • Specifying Line Styles and Colors 3-
    • Plotting Lines and Markers 3-
    • Graphing Imaginary and Complex Data 3-
    • Adding Plots to an Existing Graph 3-
    • Figure Windows 3-
    • Displaying Multiple Plots in One Figure 3-
    • Controlling the Axes 3-
    • Adding Axis Labels and Titles 3-
    • Saving Figures 3-
  • Creating Mesh and Surface Plots 3-
    • About Mesh and Surface Plots 3-
    • Visualizing Functions of Two Variables 3-
  • Plotting Image Data 3-
    • About Plotting Image Data 3-
    • Reading and Writing Images 3-
  • Printing Graphics 3-
    • Overview of Printing 3-
    • Printing from the File Menu 3-
    • Exporting the Figure to a Graphics File 3-
    • Using the Print Command 3-
  • Understanding Handle Graphics Objects 3-
    • Using the Handle 3-
    • Graphics Objects 3-
    • Setting Object Properties 3-
    • Specifying the Axes or Figure 3-
    • Finding the Handles of Existing Objects 3-
  • Flow Control 4-
    • Conditional Control — if, else, switch 4-
    • Loop Control — for, while, continue, break 4-
    • Error Control — try, catch 4-
    • Program Termination — return 4-
  • Other Data Structures 4-
    • Multidimensional Arrays 4-
    • Cell Arrays 4-
    • Characters and Text 4-
    • Structures 4-
  • Scripts and Functions 4-
    • Overview 4-
    • Scripts 4-
    • Functions 4-
    • Types of Functions 4-
    • Global Variables 4-
    • Passing String Arguments to Functions 4-
    • The eval Function 4-
    • Function Handles 4-
    • Function Functions 4-
    • Vectorization 4-
    • Preallocation 4-
  • Object-Oriented Programming 4-
    • MATLAB Classes and Objects 4-
    • Learn About Defining MATLAB Classes 4-
  • Introduction 5-
  • Preprocessing Data 5-
    • Overview 5-
    • Loading the Data 5-
    • Missing Data 5-
    • Outliers 5-
    • Smoothing and Filtering 5-
  • Summarizing Data 5-
    • Overview 5-
    • Measures of Location 5-
    • Measures of Scale 5-
    • Shape of a Distribution 5-
  • Visualizing Data 5-
    • Overview 5-
    • 2-D Scatter Plots 5-
    • 3-D Scatter Plots 5-
    • Scatter Plot Arrays 5-
    • Exploring Data in Graphs 5-
  • Modeling Data 5-
    • Overview 5-
    • Polynomial Regression 5-
    • General Linear Regression 5-
  • What Is GUIDE? 6-
  • Laying Out a GUI 6-
    • Starting GUIDE 6-
    • The Layout Editor 6-
  • Programming a GUI 6-
  • Desktop Overview 7-
    • Introduction to the Desktop 7-
    • Arranging the Desktop 7-
    • Start Button 7-
  • Command Window and Command History 7-
    • Command Window 7-
    • Command History 7-
  • Getting Help 7-
    • Ways to Get Help 7-
      • Help Browser 7- Accessing Documentation, Examples, and Demos Using the
    • Searching for Documentation and Demos 7-
    • Browsing for Documentation and Demos 7-
    • Running Demos and Code in Examples 7-
  • Workspace Browser and Variable Editor 7-
    • Workspace Browser 7-
    • Variable Editor 7-
  • Managing Files in MATLAB 7-
    • How MATLAB Helps You Manage Files 7-
    • Making Files Accessible to MATLAB 7-
    • Using the Current Folder Browser to Manage Files 7-
    • More Ways to Manage Files 7-
    • File Exchange 7- Finding and Getting Files Created by Other Users —

Editor............................................ 7-

Editing MATLAB Code Files........................ 7-

Identifying Problems and Areas for Improvement....... 7-

Publishing MATLAB Code Files..................... 7-

Improving and Tuning Your MATLAB Programs..... 7-

Finding Errors Using the Code Analyzer Report........ 7-

Improving Performance Using the Profiler............. 7-

External Interfaces

Programming Interfaces........................... 8-

Call MATLAB Software from C/C++ and Fortran

Programs...................................... 8-

Call C/C++ and Fortran Programs from MATLAB Command

Line.......................................... 8-

Call Sun Java Commands from MATLAB Command

Line.......................................... 8-

Call Functions in Shared Libraries................... 8-

Import and Export Data............................ 8-

Interface to .NET Framework....................... 8-

Component Object Model Interface.................. 8-

Web Services...................................... 8-

Serial Port Interface............................... 8-

Index

xi

_

Getting Started

The MATLAB ®^ high-performance language for technical computing integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. You can watch the Getting Started with MATLAB video demo for an overview of the major functionality. If you have an active Internet connection, you can also watch the Working in the Development Environment video demo, and the Writing a MATLAB Program video demo. This collection includes the following topics:

Chapter 1, Introduction (p. 1-1) Describes the components of the MATLAB system Chapter 2, Matrices and Arrays (p. 2-1)

How to use MATLAB to generate matrices and perform mathematical operations on matrices Chapter 3, Graphics (p. 3-1) How to plot data, annotate graphs, and work with images Chapter 4, Programming (p. 4-1) How to use MATLAB to create scripts and functions, how to construct and manipulate data structures Chapter 5, Data Analysis (p. 5-1) How to set up a basic data analysis Chapter 6, Creating Graphical User Interfaces (p. 6-1)

Introduces GUIDE, the MATLAB graphical user interface development environment. Chapter 7, Desktop Tools and Development Environment (p. 7-1)

Information about tools and the MATLAB desktop Chapter 8, External Interfaces (p. 8-1)

Introduces external interfaces available in MATLAB software.

Getting Started

A printable version (PDF) of this documentation is available on the Web—MATLAB Getting Started Guide. For tutorial information about any of the topics covered in this collection, see the corresponding sections in the MATLAB documentation. For reference information about MATLAB functions, see the MATLAB Function Reference.

1 Introduction

Product Overview

In this section... “Overview of the MATLAB Environment” on page 1- “The MATLAB System” on page 1-

Overview of the MATLAB Environment MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. Using the MATLAB product, you can solve technical computing problems faster than with traditional programming languages, such as C, C++, and Fortran.

You can use MATLAB in a wide range of applications, including signal and image processing, communications, control design, test and measurement, financial modeling and analysis, and computational biology. Add-on toolboxes (collections of special-purpose MATLAB functions, available separately) extend the MATLAB environment to solve particular classes of problems in these application areas.

MATLAB provides a number of features for documenting and sharing your work. You can integrate your MATLAB code with other languages and applications, and distribute your MATLAB algorithms and applications. Features include:

- High-level language for technical computing - Development environment for managing code, files, and data - Interactive tools for iterative exploration, design, and problem solving - Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization, and numerical integration - 2-D and 3-D graphics functions for visualizing data - Tools for building custom graphical user interfaces

Product Overview

- Functions for integrating MATLAB based algorithms with external applications and languages, such as C, C++, Fortran, Java™, COM, and Microsoft®^ Excel ®

The MATLAB System

The MATLAB system consists of these main parts:

Desktop Tools and Development Environment

This part of MATLAB is the set of tools and facilities that help you use and become more productive with MATLAB functions and files. Many of these tools are graphical user interfaces. It includes: the MATLAB desktop and Command Window, an editor and debugger, a code analyzer, and browsers for viewing help, the workspace, and folders.

Mathematical Function Library

This library is a vast collection of computational algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.

The Language

The MATLAB language is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both “programming in the small” to rapidly create quick programs you do not intend to reuse. You can also do “programming in the large” to create complex application programs intended for reuse.

Graphics

MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications.

Documentation

Documentation

The MATLAB program provides extensive documentation, in both printable and HTML format, to help you learn about and use all of its features. If you are a new user, begin with this Getting Started guide. It covers all the primary MATLAB features at a high level, including many examples.

To view the online documentation, select Help > Product Help in MATLAB. Online help appears in the Help browser, providing task-oriented and reference information about MATLAB features. For more information about using the Help browser, see “Getting Help” on page 7-7.

The MATLAB documentation is organized into these main topics:

- Desktop Tools and Development Environment — Startup and shutdown, arranging the desktop, and using tools to become more productive with MATLAB - Data Import and Export — Retrieving and storing data, memory-mapping, and accessing Internet files - Mathematics — Mathematical operations - Data Analysis — Data analysis, including data fitting, Fourier analysis, and time-series tools - Programming Fundamentals — The MATLAB language and how to develop MATLAB applications - Object-Oriented Programming — Designing and implementing MATLAB classes - Graphics — Tools and techniques for plotting, graph annotation, printing, and programming with Handle Graphics ®^ objects - 3-D Visualization — Visualizing surface and volume data, transparency, and viewing and lighting techniques - Creating Graphical User Interfaces — GUI-building tools and how to write callback functions - External Interfaces — MEX-files, the MATLAB engine, and interfacing to Sun Microsystems™ Java software, Microsoft ®^ .NET Framework, COM, Web services, and the serial port

1 Introduction

There is reference documentation for all MATLAB functions:

- Function Reference — Lists all MATLAB functions, listed in categories or alphabetically - Handle Graphics Property Browser — Provides easy access to descriptions of graphics object properties - C/C++ and Fortran API Reference — Covers functions used by the MATLAB external interfaces, providing information on syntax in the calling language, description, arguments, return values, and examples

The MATLAB online documentation also includes:

- Examples — An index of examples included in the documentation - Release Notes — New features, compatibility considerations, and bug reports for current and recent previous releases - Printable Documentation — PDF versions of the documentation, suitable for printing

In addition to the documentation, you can access demos for each product from the Help browser. Run demos to learn about key functionality of MathWorks ® products and tools.