Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 142 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
142
Dung lượng
1,71 MB
Nội dung
ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14 th , 2007 1 ELE 532 – Signals and Systems Fall 2007 MATLAB Tutorial Raymond Phan Distributed Multimedia Computing Research (DMCR) Lab Ryerson University – EPH 237 rphan@ee.ryerson.ca http://www.ee.ryerson.ca/~rphan/ele532/MATLABTutorial.ppt ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 2 Outline of Tutorial – (1) • Introduction • Getting Started • Variables and Starting Basics • Vectors and Matrices • Basic Operations • Script Files • Function Script Files ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 3 Outline of Tutorial – (2) • Flow Control • Basic Graphics Commands • Other Useful Commands • Final Words ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 4 Introduction – (1) • So… what the hell is MATLAB and what’s it all about? – MATLAB: MATrix LABoratory • Created in 1970 by a dude named Cleve Moler • Was (and still is) used extensively at Stanford University and the University of New Mexico – Why? To make calculating the following things a lot easier! • Matrix Theory • Linear Algebra • Numerical Analysis ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 5 Introduction – (2) • MATLAB is selected as a numerical analysis tool over languages like C and Java because: – Very EASY programming language – Powerful graphics capabilities – Very sleek and interactive interface – Great for general scientific and engineering computation • Later in your courses, you’re going to start to use this heavily, especially in: – ELE 639: Control Systems – ELE 792: Digital Signal Processing – … any signal processing and controls course in 4 th year ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 6 Outline of Tutorial – (1) • Introduction • Getting Started • Variables and Starting Basics • Vectors and Matrices • Basic Operations • Script Files • Function Script Files ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 7 Getting Started – (1) • Where can I find and use MATLAB? • Method #1: On the EE undergraduate network labs: – ENG 406, 407, 408 and 409 • Log onto an EE undergraduate terminal • A) Go to Applications – Accessories – Terminal and type in ‘matlab’ (without the quotes) • B) Go to Applications – Math – MATLAB 2007a ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 8 Getting Started – (2) • Method #2: If you don’t feel like using the computers at school, you can install your own copy of MATLAB on your PC or laptop – There are many ways to obtain your own copy: • Buy a student version at the Ryerson Bookstore • Obtain a trial version online via: http://www.mathworks.com • “Borrow” from a friend – Version of MATLAB needed for these labs: MATLAB 7.0 and up – NOTE!: You MUST have the Java Runtime Environment (JRE) installed on your system • At LEAST 5.0 and up – MATLAB uses the JRE as a backbone to run the whole application ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 9 Getting Started – (3) • What happens next!? – MATLAB Interface: >> means it’s ready for input from you ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 10 Outline of Tutorial – (1) • Introduction • Getting Started • Variables and Starting Basics • Vectors and Matrices • Basic Operations • Script Files • Function Script Files [...]... and you start from scratch • clc command: Flushes the command prompt – Variables will still be in the workspace, but it clears the command prompt screen ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 17 Variables and Basic Commands – (8) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 18 Variables and Basic Commands – (9) • Can also declare complex... – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 15 Variables and Basic Commands – (6) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 16 Variables and Basic Commands – (7) • who command: Shows you all of the variables created by you – You can also check the workspace as well • clear command: Clears all of the variables shown in the workspace, and you start... created and can be accessed • Right: Command Prompt – Enter commands and variable declarations here – Commands without a semicolon ( ; ) echo your command to screen – Commands with a semicolon suppress that output ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 14 Variables and Basic Commands – (5) • Can enter commands either: – One at a time: The end of each command, press... – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 20 Variables and Basic Commands – (11) • Command History window: Used to keep track of the commands you ran recently • You can also double click on any of the commands to re-run them again • You can also press the up & down keys to cycle through the commands as well in the command prompt ELE 532 – Signals and Systems MATLAB Tutorial. .. ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 12 Variables and Basic Commands – (3) • Some valid variable names: – – – – voltage valueOfR1 Ron _and_ Mauro _Alan2007_ • Some invalid variable names (why are these invalid?): – – – – 123 value of R1 3v X#*()$#$!!! ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 13 Variables and Basic Commands – (4)... matrix, a, and assign it to Joe • You can also do the 2nd line too It’s exactly the same meaning ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 33 Vectors and Matrices – (12) • Example Time! • 1) How do we define M in MATLAB syntax? • 2) How do we execute a), b), c) and d)? ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 34 Vectors and Matrices... they start at index 1! ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 25 Vector and Matrices – (4) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 26 Vector and Matrices – (5) • How do I create a matrix in MATLAB? – C or Java way: int a[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; – MATLAB way: • #1: a = [1 2 3 4; 5... of the columns! ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 30 Vectors and Matrices – (9) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 31 Vectors and Matrices – (10) • Some more examples: – – – – sally sally sally sally = = = = a(2,3); a(1:3,3:4); a(:, 1:3); a(2:4,:); • 1st line: Access 2nd row, 3rd column element, and assign it to sally •... between rows 1 – 3, and columns 3 – 4 and assign this to sally • 3rd line: Get a matrix with elements between columns 1 – 3 and give me every possible row, and assign this to sally • 4th line: Get a matrix with elements between rows 2 – 4 and give me every possible column, and assign this to sally ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 32 Vectors and Matrices – (11)... value: 1 x 1 matrix • Why does MATLAB decide to handle it this way? – You’ll see later that handling variables as matrices makes things A LOT faster and easier to work with ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 23 Vectors and Matrices – (2) • How do you declare a vector / array in MATLAB? – C or Java way: int a[4] = {1, 2, 3, 4}; – MATLAB way: • a = [1 2 3 4] – row . called ans (answer) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 16 Variables and Basic Commands – (6) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September. ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14 th , 2007 1 ELE 532 – Signals and Systems Fall 2007 MATLAB Tutorial Raymond Phan Distributed Multimedia. Systems MATLAB Tutorial Friday, September 14th, 2007 18 Variables and Basic Commands – (8) ELE 532 – Signals and Systems MATLAB Tutorial Friday, September 14th, 2007 19 Variables and Basic Commands –