Unformatted text preview:

Introduction to MATLABSlide 2PLEASE START MATLAB NOW from Windows XPC Language (vs) MATLAB (some things to remember!)MATLABSlide 6MATLAB DisplayMATLAB’s Working DirectoryMATLAB Variable NamesMATLAB Special Variable ( do not use as variable names ! )MATLAB Math & Assignment OperatorsOther MATLAB symbolsMATLAB MatricesSlide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Extracting a Sub-MatrixSlide 26Slide 27Reading Data from filesPlotting with MATLABSlide 30Slide 31Slide 32Some Useful MATLAB commandsSlide 34A Useless, But Interesting, MATLAB commandMATLAB Relational OperatorsMATLAB Logical OperatorsMATLAB Logical FunctionsMATLAB Display formatsMATLAB Selection StructuresMATLAB Repetition StructuresScalar - Matrix AdditionScalar - Matrix SubtractionScalar - Matrix MultiplicationScalar - Matrix DivisionSupplemental Information Viewing a MATLAB fileSlide 47Supplemental Information Other commandsSupplemental Information Other commandsSlide 50Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 1Winter QuarterIntroduction to MATLABLecture 18Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 2Winter QuarterIntroduction to MATLABLecture 18Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionPLEASE START MATLAB NOW from Windows XP•use the icon •or select start / All programs / MATLAB•The following prompt should appear in the command window after a fairly long initialization process: >>Lect 18 P. 3Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionC Language (vs) MATLAB (some things to remember!)C Language (compiler) MATLAB (interpreter) { }not needed for blocks, use 'end'= { }; = [ ] for data assignment pow(a,b); a ^ b ; used to suppress output and to separate rows in matrices declare variables MATLAB does it for you '' usually is a single ' ! ~ ?? variables stored as matrices // or /* … */ % Comments && …. || & …. | Lect 18 P. 4Winter QuarterEngineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 5Winter QuarterMATLAB•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.Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 6Winter QuarterMATLAB•The MATLAB environment is command oriented somewhat like UNIX. A prompt appears on the screen and a MATLAB statement can be entered. When the <ENTER> 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.•The following slide shows the various MATLAB windows.Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionMATLAB DisplayCommand Window (where commands are entered)Current Directory (lists file, etc.)Command History (what has been typed)Workspace (variable values)Command prompt8-9Lect 18 P. 7Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionMATLAB’s Working DirectoryWhen you first start MATLAB it is a good practice to changethe working directory to your N: drive or USB device.directory may also be changed by using the UNIX cd command.. >> cd N:and the contents can be displayed using the ls or dir command … >> ls)or use BrowseButtonLect 18 P. 8Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 9Winter QuarterMATLAB Variable Names•Variable names ARE case sensitive•Variable names can contain up to 63 characters (as of MATLAB 6.5 and newer)•Variable names must start with a letter followed by letters, digits, and underscores.Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 10Winter QuarterMATLAB Special Variable( do not use as variable names ! )ans Default variable name for resultspi Value of  eps Smallest incremental numberinf InfinityNaN Not a number e.g. 0/0i and j i = j = square root of -1 // so don't use i in loopsrealmin The smallest usable positive real numberrealmax The largest usable positive real numberEngineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 11Winter QuarterMATLAB Math & Assignment OperatorsPower ^ or .^ a^b or a.^bMultiplication * or .* a*b or a.*bDivision / or ./ a/b or a./b or \ or .\ b\a or b.\aNOTE: 56/8 = 8\56 - (unary) + (unary)Addition + a + bSubtraction - a - bAssignment = a = b (assign b to a)( “dot operators” do element by element computations )Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 12Winter QuarterOther MATLAB symbols>> prompt. . . continue statement on next line, separate statements and data% start comment which ends at end of line; (1) suppress output(2) used as a row separator in a matrix : specify rangeEngineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionLect 18 P. 13Winter QuarterMATLAB Matrices•MATLAB treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored. •Vectors are special forms of matrices and contain only one row OR one column.•Scalars are matrices with only one row AND one columnEngineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education CoalitionARITHMETIC OPERATIONS WITH SCALARS11 OperationAdditionSubtractionMultiplicationRight DivisionLeft DivisionExponentiationSymbol+-*/\^Example5 + 35 - 35 * 35 / 35 \ 3 = 3 / 55 ^ 3Lect 18 P. 14Engineering H192 - Computer ProgrammingThe Ohio State UniversityGateway Engineering Education


View Full Document

OSU ENGR H192 - Introduction to MATLAB

Documents in this Course
Strings

Strings

22 pages

Load more
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?