Content 1Introduction to MATLAB 2MATLAB Basics 3Branching Statements and Program Design 4Loops 5User-Defined Functions 6Complex Data, Character Data, and Additional Plot Types 7Sparse Arrays, Cell Arrays, and Structures 8Input/Output Functions 9Handle Graphics 10Graphical User Interfaces
1.1 The Advantages of MATLAB 1.2 Disadvantages of MATLAB 1.3 The MATLAB Environment 1.4 Using MATLAB as a Scratchpad 1.5 Summary Chapter 1 Introduction to MATLAB
Introduction The five parts of MATLAB Development Environment ： This is the set of tools and facilities that help you use MATLAB functions and files. The MATLAB Mathematical Function Library. MATLAB Language Graphics ： MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. The MATLAB Application Program Interface (API) ： This is a library that allows you to write C and Fortran programs that interact with MATLAB.
Introduction MATLAB----short for MATrix LABoratory A Huge Program Note: More than 1000 functions in basic MATLAB Compared: C language----about 300 Fortran-77----about 50 Compared: C language----about 300 Fortran-77----about 50 Various Toolkits Example: Communication Toolbox, Filter Design Toolbox, Image Processing Toolbox… The course makes no attempt to introduce you to all of MATLAB’s functions. Instead, you learn the basics of how to write, debug, and optimize good MATLAB programs with a subset of the most important functions.
1.1 The Advantages of MATLAB Ease of use Platform independence Predefined functions Device-Independent Plotting Graphical User Interface MATLAB Compiler
1.2 Disadvantages of MATLAB Can be slow Reason----MATLAB is an interpreted language Resolvent----Compile the program before distribution Expensive 5 to 10 times more expensive than C compiler Cost-effective for businesses
1.3 MATLAB Environment Fundamental unit of data----array MATLAB Desktop –Command Window –Figure Windows –Edit/Debug Window –Command History Window –Launch Pad –Workspace Browser and Array Editor –Help Browser –Current Directory Browser
1.3.1 MATLAB Desktop Workspace Browser Command Window Current Directory Browser Command History Window To view or change the current directory Help Browser
The command prompt(>>) Example: Calculate the area of a circle with a radius of 2.5m x1=1+1/2+1/3+1/4+1/5+1/6; x1=1+1/2+1/3+1/4… +1/5+1/6; 1.3.2 The Command Window area = pi * 2.5^2 π is predefined,use pi without first declaring Ellipsis(…),continuing on the next line
Script file Combined with a series of commands Executed by typing file-name in the Command Window Also known as M-files 1.3.2 The Command Window
Re-execute----double click with the left mouse button Delete----as shown in upper figure 1.3.3 The Command History Window
Workspace----A collection of all the variables and arrays Some useful commands: >> whos List variables and arrays in current workspace >>var1 Determine the content of any variable and array >>clear var1 var2 … Delete var1 and var2. Simply “clear” deletes all variables 1.3.7 The MATLAB Workspace
Use the Help Browser –Selecting the Help icon –Typing helpdesk or helpwin in the Command window 1.3.9 Getting Help
Command-line oriented way to get help –Type help or help fun1 in the command window Search for an exact function name match –Type lookfor command Search the quick summary information in each function for a match 1.3.9 Getting Help Suppose that you were looking for a function to take the reverse of a matrix. You think that the function name may be “inverse”. For example:
Type demo or select “demos” in the Launch Pad clc----clear the contents of Command Window clf----clear the contents of Figure Window clear----clear the variables in the Workspace ^c (control-c)----abort !----Invoke operating system command diary----echo a copy of all input and most output typed in the Command Window to the diary file (diary filename, diary off,diary on) 1.3.10 A Few Important Commands
Search Path----Be used to find M-files Enter a name at the MATLAB prompt –Look for the name as a variable –Check to see if it is a built-in function or command –Check to see if it is an M-file in the current directory –Check to see if it is an M-file in any directory in the search path 1.3.11 The MATLAB Search Path
Programming Pitfalls –Never use a variable with the same name as a MATLAB function or command –Never create an M-file with the same name as a MATLAB function or command Examine and modify search path –“File/Set Path”, Path Tool, editpath –path command 1.3.11 The MATLAB Search Path
Using the symbols +,-,*,/,^ For example Calculate the volume of a cylinder of radius r and length l. >> r=0.1; >> l=0.5; >> V=A*l; >> A=pi*r^2; >> V=A*l V = 0.0157 1.4 Using MATLAB as a Scratchpad
1.1 The Advantages of MATLAB 1.2 Disadvantages of MATLAB 1.3 The MATLAB Environment 1.4 Using MATLAB as a Scratchpad 1.5 Summary
Your consent to our cookies if you continue to use this website.