U of U CS 6640 - Introduction to Matlab

Unformatted text preview:

Tutorial 1: Introduction to MATLAB Page 1 of 12 10/07/2003 Tutorial 1♣: Introduction to MATLAB Daniela Raicu [email protected] School of Computer Science, Telecommunications, and Information Systems DePaul University, Chicago, IL 60604 The purpose of this tutorial is to present basics of MATLAB. We do not assume any prior knowledge of this package; this tutorial is intended for users running a professional version of MATLAB 6.5, Release 13. Topics discussed in this tutorial include: 1. Introduction to MATLAB and its toolboxes 2. Development environment 3. MATLAB help and basics 4. MATLAB Toolboxes demos 5. MATLAB Programming 6. MATLAB resources on the Internet 7. MATLAB toolboxes descriptions 1.0 MATLAB and its toolboxes MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and visualization. It integrates numerical analysis, matrix computation, signal processing, and graphics in an easy-to-use environment. MATLAB also features a family of application-specific solutions called toolboxes. Toolboxes are comprehensive collections of MATLAB functions that extend its environment in order to solve particular classes of problems. The table below includes the toolboxes that are available in the last version of MATLAB: Communications Image Processing System Identification Control System Instrument Control Wavelet Data Acquisition Mapping MATLAB Compiler Database Neural Network MATLAB C/C++ Graphics Library Datafeed Optimization MATLAB C/C++ Math Library Filter Design Partial Differential Equation MATLAB Report Generator Financial Robust Control MATLAB Runtime Server Frequency Domain System Identification Signal Processing MATLAB Web Server Fuzzy Logic Statistics Simulink Higher-Order Spectral Analysis Spline Symbolic/Extended Math ♣ Event Sponsor: Visual Computing Area Curriculum Quality of Instruction Council (QIC) grantTutorial 1: Introduction to MATLAB Page 2 of 12 10/07/2003 2.0 Development Environment: Command Window You can start MATLAB by double clicking on the MATLAB icon that should be on the desktop of your computer. This brings up the window called the Command Window. This window allows a user to enter simple commands. To perform a simple computations type a command and next press the Enter or Return key. For instance, >> s = 1 + 2 s = 3 Note that the results of these computations are saved in variables whose names are chosen by the user. If they will be needed during your current MATLAB session, then you can obtain their values typing their names and pressing the Enter or Return key. For instance, >> s s = 3 Variable name begins with a letter, followed by letters, numbers or underscores. MATLAB recognizes only the first 31 characters of a variable name. Figure 1: A screenshot of the development environment, command windows For a demo for the MATLAB Desktop, you can visit http://www.mathworks.com/products/demos/# (there is also a demo for the Command History and Workspace Browser). To close MATLAB type exit in the Command Window and next press Enter or Return key. A second way to close your current MATLAB session is to select File in the MATLAB's toolbar and next click on Exit MATLAB option. All unsaved information residing in the MATLAB Workspace will be lost.Tutorial 1: Introduction to MATLAB Page 3 of 12 10/07/2003 3.0 MATLAB Help and Basics To get help type “help” (will give you a list of help topics) or “help topic”. If you don't know the exact name of the topic or command you are looking for, type "lookfor keyword" (e.g., "lookfor regression") When writing a long MATLAB statement that exceeds a single row use “...” to continue statement to next row. When using the command line, a ";" at the end means MATLAB will not display the result. If ";" is omitted then MATLAB will display result. Use the up-arrow to recall commands without retyping them (and down arrow to go forward in commands). The symbol "%" is used in front of a comment. Figure 2: A screenshot of HelpTutorial 1: Introduction to MATLAB Page 4 of 12 10/07/2003 4.0 MATLAB Toolboxes Demos To learn more about MATLAB capabilities you can execute the demo command in the Command Window or click on Help and next select Demos from the pull-down menu. Some of the MATLAB demos use both the Command and the Figure windows. Figure 3: A screenshot of Demos’ Help Figure 4: A screenshot of the image processing demoTutorial 1: Introduction to MATLAB Page 5 of 12 10/07/2003 5.0 MATLAB Programming %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Introducing MATLAB (adapted from http://www.cns.nyu.edu/~eero and % http://www.cs.dartmouth.edu/~farid/teaching/cs88/MATLAB.intro.html) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % (1) Objects in MATLAB -- the basic objects in MATLAB are scalars, vectors, and matrices... N = 5 % a scalar v = [1 0 0] % a row vector v = [1;2;3] % a column vector v = v' % transpose a vector v = [1:.5:3] % a vector in a specified range: v = pi*[-4:4]/4 % [start: stepsize: end] v = [] % empty vector m = [1 2 3; 4 5 6] % a matrix: 1ST parameter is ROWS % 2ND parameter is COLS m = zeros(2,3) % a matrix of zeros v = ones(1,3) % a matrix of ones m = eye(3) % identity matrix v = rand(3,1) % rand matrix (see also randn) v = [1 2 3]; % access a vector element v(3) %vector(number) m = [1 2 3; 4 5 6] m(1,3) % access a matrix element % matrix(rownumber, columnnumber) m(2,:) % access a matrix row (2nd row) m(:,1) % access a matrix column (1st row) size(m) % size of a matrix size(m,1) % number rows size(m,2) % number of columns m1 = zeros(size(m)) % create a new matrix with size of m who % list of variables whos % list/size/type of variables %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % (2) Simple operations on vectors and matrices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % (A) Pointwise (element by element) Operations: % addition of vectors/matrices and multiplication by a scalar % are done "element by element" a= [1 2 3 4]; % vector 2 * a % scalar multiplication a / 4 % scalar multiplicationTutorial 1: Introduction to MATLAB Page 6 of 12 10/07/2003 b = [5 6 7 8]; % vector a + b


View Full Document

U of U CS 6640 - Introduction to Matlab

Download Introduction to Matlab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Matlab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Matlab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?