Matlab tutorial for beginners ppt

what is simulink in matlab with example and matlab lecture notes ppt
Dr.MattWood Profile Pic
Dr.MattWood,United States,Teacher
Published Date:25-07-2017
Your Website URL(Optional)
Comment
6.094 Introduction to Programming in MATLAB Lecture 1: Variables, Scripts, and Operations Danilo Šćepanović IAP 2010¾¾¾ Getting Started • To get MATLAB Student Version for yourself » https://msca.mit.edu/cgi-bin/matlab Use VPN client to enable off-campus access Note: MIT certificates are required • Open up MATLAB for Windows Through the START Menu • On Athena » add matlab » matlab &Current directory Workspace Command Window Command History Courtesy of The MathWorks, Inc. Used with permission.Making Folders • Use folders to keep your programs organized • To make a new folder, click the ‘Browse’ button next to ‘Current Directory’ • Click the ‘Make New Folder’ button, and change the name of the folder. Do NOT use spaces in folder names. In the MATLAB folder, make two new folders: IAPMATLAB\day1 • Highlight the folder you just made and click ‘OK’ • The current directory is now the folder you just created • To see programs outside the current directory, they should be in the Path. Use File- Set Path to add folders to the path¾ Æ Customization • File Preferences Allows you personalize your MATLAB experience Courtesy of The MathWorks, Inc. Used with permission.¾¾¾¾ MATLAB Basics • MATLAB can be thought of as a super-powerful graphing calculator Remember the TI-83 from calculus? With many more buttons (built-in functions) • In addition it is a programming language MATLAB is an interpreted language, like Java Commands executed line by line¾¾ Help/Docs • help The most important function for learning MATLAB on your own • To get info on how to use a function: » help sin Help lists related functions at the bottom and links to the doc • To get a nicer version of help with examples and easy-to- read descriptions: » doc sin • To search for a function by specifying keywords: » doc + Search tab¾¾¾ Scripts: Overview • Scripts are collection of commands executed in sequence written in the MATLAB editor saved as MATLAB files (.m extension) • To create an MATLAB file from command-line » edit helloWorld.m • or click Courtesy of The MathWorks, Inc. Used with permission.Scripts: the Editor Means that it's not saved Line numbers MATLAB file Real-time Debugging tools path error check Help file Comments Possible breakpoints Courtesy of The MathWorks, Inc. Used with permission.¾¾¾ Scripts: Some Notes • COMMENT Anything following a % is seen as a comment The first contiguous comment becomes the script's help file Comment thoroughly to avoid wasting time later • Note that scripts are somewhat static, since there is no input and no explicit output • All variables created and modified in a script exist in the workspace even after it has stopped runningExercise: Scripts Make a helloWorld script • When run, the script should display the following text: Hello World I am going to learn MATLAB • Hint: use disp to display strings. Strings are written between single quotes, like 'This is a string'Exercise: Scripts Make a helloWorld script • When run, the script should display the following text: Hello World I am going to learn MATLAB • Hint: use disp to display strings. Strings are written between single quotes, like 'This is a string' • Open the editor and save a script as helloWorld.m. This is an easy script, containing two lines of code: » % helloWorld.m » % my first hello world program in MATLAB » disp('Hello World'); » disp('I am going to learn MATLAB');¾¾¾ Variable Types • MATLAB is a weakly typed language No need to initialize variables • MATLAB supports various types, the most often used are » 3.84 64-bit double (default) » ‘a’ 16-bit char • Most variables you’ll deal with will be vectors or matrices of doubles or chars • Other types are also supported: complex, symbolic, 16-bit and 8 bit integers, etc. You will be exposed to all these types through the homework¾¾¾¾¾¾¾¾ Naming variables • To create a variable, simply assign a value to a name: » var1=3.14 » myString=‘hello world’ • Variable names first character must be a LETTER after that, any combination of letters, numbers and _ CASE SENSITIVE (var1 is different from Var1) • Built-in variables. Don’t use these names i and j can be used to indicate complex numbers pi has the value 3.1415926… ans stores the last unassigned value (like on a calculator) Inf and -Inf are positive and negative infinity NaN represents ‘Not a Number’¾ Scalars • A variable can be given a value explicitly » a = 10 shows up in workspace • Or as a function of explicit values and existing variables » c = 1.345-2a • To suppress output, end the line with a semicolon » cooldude = 13/3;Arrays • Like other programming languages, arrays are an important part of MATLAB • Two types of arrays (1) matrix of numbers (either double or complex) (2) cell array of objects (more advanced data structure) MATLAB makes vectors easy That’s its powerRow Vectors • Row vector: comma or space separated values between brackets » row = 1 2 5.4 -6.6 » row = 1, 2, 5.4, -6.6; • Command window: • Workspace: Courtesy of The MathWorks, Inc. Used with permission.Column Vectors • Column vector: semicolon separated values between brackets » column = 4;2;7;4 • Command window: • Workspace: Courtesy of The MathWorks, Inc. Used with permission.¾¾¾ size & length • You can tell the difference between a row and a column vector by: Looking in the workspace Displaying the variable in the command window Using the size function • To get a vector's length, use the length function¾ Matrices • Make matrices like vectors 12 ⎡⎤ • Element by element a = ⎢⎥ 34 » a= 1 2;3 4; ⎣⎦ • By concatenating vectors or matrices (dimension matters) » a = 1 2; » b = 3 4; » c = 5;6; » d = a;b; » e = d c; » f = e e;a b a; » str = 'Hello, I am ' 'John'; Strings are character vectors

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.