Professional Documents
Culture Documents
MATLAB Basics
MATLAB Basics
2
GETTING STARTED WITH THE MATLAB ENVIRONMENT :
Double clicking the shortcut icon will open the MATLAB environment.
Command
History
window
3
CURRENT DIRECTORY WINDOW :
4
COMMAND WINDOW :
Command window
Commands are executed in the
command window.
MATLAB’s responses are displayed in the
command window.
Command prompt is denoted by the
symbol
You can type your commands at the
command prompt.
5
CURRENT DIRECTORY WINDOW :
6
CURRENT DIRECTORY WINDOW :
It is possible to
change the size and shape of the
window.
change the location of the window.
close the window.
7
MATLAB AS A CALCULATOR:
Arithmetic operations:
+ addition
− subtraction
∗ multiplication
/ division
^ exponentiation
Try it: Compute 3 divided by 4, then multiply the result by 2, and then
raise the result to the 3rd power.
3×4
Try it: Compute
22 +4Τ2
8
BASIC ARITHMETIC FUNCTIONS:
MATLAB has many basic arithmetic functions like sin, cos, tan, asin,
acos, atan, exp, log, log10, and sqrt.
Input to these functions are always placed inside of parentheses.
Try it: Find square root of 9
Try it: Compute sin 𝜋Τ2
Try it: Compute 𝑒 𝑙𝑜𝑔10
9
FORMAT SHORT LONG AND BANK:
Default setting of MATLAB is short format.
This format displays all numbers to four significant digits.
The long format displays the maximum number of digits that
MATLAB can store,
The bank format displays exactly two significant digits.
The format can be changed using the following commands:
>> format short
>> format long
>> format bank
Try it: Display the value of 𝜋 using short, long and bank format
Note: This changes only how the numbers are displayed. 10
INF, NAN AND IMAGINARY NUMBER 𝑖:
1 1 0
Try it: Compute , , , , ×2
0 0
11
COMPARISON OPERATORS:
Comparison operators compare the value of two numbers.
They are used to build logical expressions.
> greater than
>= greater than or equal
< less than
<= less than or equal
~= not equal
== equal
A logical expression that is true will compute to the value “TRUE” which is
equivalent to 1.
A false expression will compute to the value “FALSE” which is equivalent to
0.
Try it: Compute the logical expression for “Is 8 equal to 9?” and “Is 3
smaller than 4?” 12
LOGICAL OPERATORS:
The fundamental logical operators are AND, OR, and NOT.
Logical AND: &&
Logical OR: ||
Logical NOT: ~
Try it: Compute
(2<4) && (3<5), (2<4) && (3>5)
(2<4) || (3<5), (2>4) && (3>5)
~(2<4)
13