Lab of comp 406 Introduction of Matlab) Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou(@comp. polyu.edu. hk Lab 1: 12 Sep, 2014
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: cspyzhou@comp.polyu.edu.hk Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Outline Matlab description Where is matlab · What is matlab Matlab Desktop MATLAB Math Operators Matrix and Array Creation, Operation. Concatenation Workspace variables Calling Functions
Outline ➢ Matlab Description • Where is Matlab • What is Matlab • Matlab Desktop • MATLAB Math Operators ➢ Matrix and Array • Creation, Operation, Concatenation ➢ Workspace Variables ➢ Calling Functions 2
What iS matlab? MATLAB MATrix LABoratory: matlab is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name is derived from MATrix Laboratory MatLab has since been expanded and now has built-in functions for solving problems requiring data analysis, signal rocessing optimization and several other types of scientific computations. It also contains functions for 2-D and 3-D graphics and animation
3 What is MATLAB ? • MATLAB – MATrix LABoratory: MATLAB is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It’s name is derived from MATrix LABoratory. – MATLAB has since been expanded and now has built-in functions for solving problems requiring data analysis, signal processing, optimization, and several other types of scientific computations. It also contains functions for 2-D and 3-D graphics and animation
Where is matlab? Find the matlab under the folder 1. Y: Win32 Matlab R2012a 2. Double click it and open Matlab Or open matlab on your computer 1. Click 'Start' 2. Click Run 3. Input ' nalwin32' 4. Find the Matlab under the folder /Network application Packages/Statistical Mathematical/Matlab Send shortcut to your folder, for example: J: starry If you have any problem, please contact the technical staffs in P0608(P508). They are very nice and helpful
Where is Matlab? • Find the Matlab under the folder – 1. Y:\Win32\Matlab\R2012a – 2. Double click it and open Matlab • Or open Matlab on your computer – 1. Click 'Start' – 2. Click 'Run' – 3. Input 'nalwin32' – 4. Find the Matlab under the folder /Network Application Packages/Statistical & Mathematical/Matlab • Send shortcut to your folder, for example: J:\starry If you have any problem, please contact the technical staffs in PQ608 (P508). They are very nice and helpful. 4
MATLAB Description Considering matlab at home Standard edition Available for roughly 2 thousand dollars Student edition Available for roughly I hundred dollars Some limitations such as the allowable size of a matrix http:/www.mathworks.com/products/matlab/
5 MATLAB Description • Considering MATLAB at home – Standard edition • Available for roughly 2 thousand dollars – Student edition • Available for roughly 1 hundred dollars. • Some limitations, such as the allowable size of a matrix http://www.mathworks.com/products/matlab/
Matlab Desktop( Cont MATLAB712.0(R2011a) x File Edit Debug Desktop window Help 日%部日0mtF贴1回 Launch pad Shortcuts a How to Add a what's New Current FolderIt口x| ommand window日 space 中口X bm·s·国№MA购回圆哈喝5 tack: Base E Select data to减 DName L >A=eye(4,4) Name△ Vaue 口 m3iregistr t registry outil +o win32 000 a deploytool bat Iworkzsngce s insttype ini p 出 cdata. xm a cdata.xsd 0 自 Current 压x Command History Hy= sin(x) irectory plot (x, y) Command xlabel(x= 0: 2\ a mexext bat Hylabel( Sine of History 回 mexsetup pm Window title( Plot of the Sine Function T mexutilspm lc m msvc modules installe clear all Details A=eye(4,4) a Start 6
6 Matlab Desktop (Cont.) Workspace Current Directory Command Window History Launch Pad
Matlab Desktop(cont Current Folder Access your files Command window Enter commands at the command line, indicated by the prompt Workspace view program variables double click on a variable to see it in the array editor Explore data that you create or import from files Command history View or rerun commands that you entered at the command line Launch pad access help, tools, demos and documentation
7 • Current Folder – Access your files • Command Window – Enter commands at the command line, indicated by the prompt (>>). • Workspace – view program variables – double click on a variable to see it in the Array Editor – Explore data that you create or import from files • Command History – View or rerun commands that you entered at the command line • Launch Pad – access help, tools, demos and documentation Matlab Desktop (cont.)
Command window The matlab environment is command oriented somewhat like UNIX. A prompt(>)appears on the screen and a matlab statement can be entered. When the key is pressed, the statement is executed, and another prompt appears If a statement is terminated with a semicolon(; ) no results will be displayed. Otherwise results will appear before the next prompt a b=a/2 b 2.5000
8 Command window • The MATLAB environment is command oriented somewhat like UNIX. A prompt (>>) appears on the screen and a MATLAB statement can be entered. When the key is pressed, the statement is executed, and another prompt appears. • If a statement is terminated with a semicolon ( ; ), no results will be displayed. Otherwise results will appear before the next prompt. » a=5; » b=a/2 b = 2.5000 »
MATLAB Math Operators Power Multiplication (matrix multiply) or . (array multiply) b or a*b Division a or ba b. a NOTE 56/8=8\56 Addition a b Subtraction a Assignment b(assign b to a) coSo Cosine value of a specific angle Sine value of a specific angle
9 MATLAB Math Operators Power ^ or .^ a^b or a.^b Multiplication * (matrix multiply) or .* (array multiply) a*b or a.*b Division / or ./ a/b or a./b or \ or .\ b\a or b.\a NOTE: 56/8 = 8\56 Addition + a + b Subtraction - a - b Assignment = a = b (assign b to a) * cos() Cosine value of a specific angle * sin() Sine value of a specific angle
As you work in MATLAB, you issue commands that ven EX1 create variables and call functions. For example, create a variable named a by typing this statement at the command Ine a=1 MATLAB adds variable a to the workspace and displays the result in the command window ry more b=2 c=a+b d=cos(a)
Ex1 • As you work in MATLAB, you issue commands that create variables and call functions. For example, create a variable named a by typing this statement at the command line: a = 1 • MATLAB adds variable a to the workspace and displays the result in the Command Window. • Try more: b = 2 c = a + b d = cos(a) 10