Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

MATLAB Basics

By : Dr. Atul R. Phadke


Associate Professor in Electrical Engineering
College of Engineering Pune (Maharashtra)
OBJECTIVES:
After studying this unit, you will be able to understand:
✓ The MATLAB environment
✓ How to execute commands in MATLAB?
✓ Basic MATLAB functions

2
GETTING STARTED WITH THE MATLAB ENVIRONMENT :
Double clicking the shortcut icon will open the MATLAB environment.

Command window Workspace


Current window
directory
window

Command
History
window

3
CURRENT DIRECTORY WINDOW :

Current directory is the folder where files


will be saved.
Current You have direct access to the files stored
directory in current directory.
window
You can change the current directory by
clicking the down arrow.
Current directory lists all the files stored
in the current directory.

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 :

Workspace window lists all the variables Workspace


currently being used. window
Command history window lists all the
previous commands entered at the
command prompt.
Command history window is helpful for
recalling the work done in previous Command
session. History
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 

Try it: Compute 𝑖 2


Try it: Compute (2 + 3𝑖) + (4 − 2𝑖)
Note: Previous commands can be recalled using UP arrow key at
command prompt and also available in command history window.

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

You might also like