MATLAB supports the following commonly used operators and special characters −OperatorPurpose+Plus; addition operator.-Minus; subtraction operator.*Scalar and matrix multiplication operator..*Array multiplication operator.^Scalar and matrix exponentiation operator..^Array exponentiation operator.\Left-division operator./Right-division operator..\Array left-division operator.:Colon; generates regularly spaced elements and represents an entire row or column.OperatorPurpose( )Parentheses; encloses function arguments and array indices; overrides precedence.[ ]Brackets; enclosures array elements..Decimal point.…Ellipsis; line-continuation operator,Comma; separates statements and elements in a row;Semicolon; separates columns and suppresses display.%Percent sign; designates a comment and specifies formatting._Quote sign and transpose operator.._Nonconjugated transpose operator.=Assignment operator.

MATLAB – BASIC SYNTAXSpecial Variables and ConstantsMATLAB supports the following special variables and constants −NameMeaningansMost recent answer.epsAccuracy of floating-point precision.i,jThe imaginary unit √-1.InfInfinity.NaNUndefined numerical result (not a number).piThe number π

MATLAB – BASIC SYNTAXNaming VariablesVariable names consist of a letter followed by any number of letters, digits or underscore.Variable names can be of any length, however, MATLAB uses only first N characters, where N is given by the functionnamelengthmax.MATLAB iscase-sensitive.

MATLAB – BASIC SYNTAXSaving Your WorkThesavecommand is used for saving all the variables in the workspace, as a file with .mat extension, in the current directory.For example,>> save myfileYou can reload the file anytime later using theloadcommand.>> load myfile

MATLAB – VARIABLESIn MATLAB environment, every variable is an array or matrix.You can assign variables in a simple way. For example,>> x = 3 % defining x and initializing it with a valueMATLAB will execute the above statement and return the following result −x = 3It creates a 1-by-1 matrix namedxand stores the value 3 in its element.

MATLAB – VARIABLESLet us check another example,>> x = sqrt(16) % defining x and initializing it with an expressionMATLAB will execute the above statement and return the following result −x = 4Please note that −•Once a variable is entered into the system, you can refer to it later.•Variables must have values before they are used.

MATLAB – VARIABLES•When an expression returns a result that is not assigned to any variable, the system assigns it to a variable named ans, which can be used later. For example,>> sqrt(78)MATLAB will execute the above statement and return the following result −ans = 8.8318

MATLAB – VARIABLESYou can use this variableans−>> sqrt(78);>> 9876 / ansMATLAB will execute the above statement and return the following result −ans = 1118.2Let’s look another example –>> x = 7 * 8;>> y = x * 7.89MATLAB will execute the above statement and return the following result −

MATLAB – VARIABLESMultiple AssignmentsYou can have multiple assignments on the same line. For

#### You've reached the end of your free preview.

Want to read all 43 pages?

- Fall '19
- Array, Advantages of MATLAB