By default, MATLAB stores all numeric values as double-precision floating point numbers. You can choose to store any number or array of numbers as integers or as single-precision numbers. All numeric types support basic array operations and mathematical operations. Conversion to Various Numeric Data Types. In the Matlab editor, Matlab parses%% delimited blocks as 'sections' which you can run as a unit independent of running the whole script.
The format command controls how MATLAB® displays numbers at the command line. If a number has extra digits that cannot be displayed in the current format, then MATLAB automatically rounds the number for display purposes. This can lead to unexpected results when combined with. MATLAB Function Reference: angle. P = angle(Z) Description. P = angle(Z) returns the phase angles, in radians, for each element of complex array Z. Parentheses are used to indicate precedence in arithmetic expressions in the usual way. They are used to enclose arguments of functions in the usual way. They are also used to enclose subscripts of vectors and matrices in a manner somewhat more general than usual. If Xand Vare vectors, then X(V)is X(V(1)), X(V(2))., X(V(n)).
MATLAB environment behaves like a super-complex calculator. You can enter commands at the >> command prompt.
MATLAB is an interpreted environment. In other words, you give a command and MATLAB executes it right away.
Type a valid expression, for example,
And press ENTER
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
Let us take up few more examples −
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
Another example,
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
Another example,
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
Another example,
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
MATLAB provides some special expressions for some mathematical symbols, like pi for π, Inf for ∞, i (and j) for √-1 etc. Nan stands for 'not a number'.
Semicolon (;) indicates end of statement. However, if you want to suppress and hide the MATLAB output for an expression, add a semicolon after the expression.
For example,
When you click the Execute button, or type Ctrl+E, MATLAB executes it immediately and the result returned is −
The percent symbol (%) is used for indicating a comment line. For example,
You can also write a block of comments using the block comment operators % { and % }.
The MATLAB editor includes tools and context menu items to help you add, remove, or change the format of comments.
MATLAB supports the following commonly used operators and special characters −
Operator | Purpose |
---|---|
+ | 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. |
./ | Array right-division operator. |
: | Colon; generates regularly spaced elements and represents an entire row or column. |
( ) | 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 supports the following special variables and constants −
Name | Meaning |
---|---|
ans | Most recent answer. |
eps | Accuracy of floating-point precision. |
i,j | The imaginary unit √-1. |
Inf | Infinity. |
NaN | Undefined numerical result (not a number). |
pi | The number π |
Variable names consist of a letter followed by any number of letters, digits or underscore.
MATLAB is case-sensitive.
Variable names can be of any length, however, MATLAB uses only first N characters, where N is given by the function namelengthmax.
The save command is used for saving all the variables in the workspace, as a file with .mat extension, in the current directory.
For example,
You can reload the file anytime later using the load command.