Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Introduction to MatLab

Matlab
• Stands for MATrix LABoratory
• Interpreted language
• Scientific programming environment
• Very good tool for the manipulation of matrices
• Great visualisation capabilities
• Loads of built-in functions
• Easy to learn and simple to use

2
What is Matlab?
• Matlab is basically a high level language which
has many specialized toolboxes for making
things easier for us
• How high?
Matlab

High Level
Languages such as
C, Pascal etc.

Assembly
Matlab Desktop

Workspace /
Current Directory
Command Window

Command
History

5
Basic MATLAB Interface

Command window:
Type your instructions
here and press ENTER
to execute them.

6
Basic MATLAB Interface

Command history: a list of


instructions executed by
MATLAB is shown here.

7
Simple calculations

8
What are we interested in?
• Matlab is too broad for our purposes in this
course.
• The features we are going to require is
Matlab
Series of
Matlab
commands
Command
m-files mat-files
Line

functions Command execution Data


Input like DOS command storage/
Output window loading
capability
Variables
• Don’t have to declare type
• Don’t even have to initialise
• Just assign in command window
>>
>> a=12; % variable a is assigned 12

Matlab comment
prompt operator
suppress
assign
command
operator
output
Try the same line without
the semicolon and
Introduction to Matlab comments
10
Sumitha Balasuriya
Some special variables and constants are:

ans Most recent answer.


eps Floating point relative accuracy.
pi π
inf ∞
NaN Not a number.

11
Some Useful MATLAB commands

what List all m-files in current directory


dir List all files in current directory
ls Same as dir
type test Display test.m in command window
delete test Delete test.m
cd a: Change directory to a:
chdir a: Same as cd
pwd Show current directory
which test Display current directory path to test.m
Click here

13
Example: search for
function mean

14
Create an m-file

To create an m-file,
1) type edit at the command
window, or
2) Press this button.

16
Create an m-file

The previous command will


display the editor window.
The editor creates an m-file
that can be used to write
your MATLAB programs.

17
Create an m-file

A lines starting with % --- is a comments

18
Save an m-file Note the file name will be changed …

To save the file press

19
Run an m-file

To execute a program, press


the RUN button.

20
Run an m-file

This window will appear. Press the


Change Directory button.

21
Run an m-file

You can see that the program has


created new variables in the
Workspace.

22
Basic
1. Arithmetic Assignment 13. If-Else & if-Else-if
2. Mathematical 14.Switch
Assignment 15.Logical Operator
3. Vector Assignment 16.Complex Number
4. Linear Equation Assignment
5. Basic Plot & Subplot 17.Inline Function
6. Basic Operation on 18. User Define Function
Matrix 19.Discontinued Graph
7. Subscripts 20.Avoid Divide by zero
8. Writing Scripts File 21.Avoid infinity
9. Operator Precedence 22.Rand function
10. Loops 23.Roll Dice Problem
11. If-Statement
12. While Statement
Matrix Operation
1. Creating Matrix
2. Concenation
3. Subscript
4. Matrix multiplication
5. Element-wise Matrix Operation
6. Repmat
7. Deletion of Row/Column
8. Eye, Magic, Pascal, Zeros, Ones
9. Diag, fliplr, flipud, rot90, tril, triu
10. Sum, Inv, Det, Eig
Differential Equation
1. First Order Differential Equation
2. Dsolve-Analytic view
3. Ode45-Numerical view
4. Symbolic view
5. Use of Debugger in Code
6. 2nd Order Differential Equation
Polynomial
1. Polynomial Representation
2. Roots of Polynomial
3. Poly, Polyval, Conv, Deconv, Polyfit

Interpolation
1. Interp2 type
2. Nearest, bilinear, bicubic, spline
Signal Processing

1. Generation of Signal
2. Step, ramp, impulse
3. Sawtooth, square
4. AM Modulation/Demodulation
5. FM Modulation/Demodulation
6. PM Modulation/Demodulation
Image Processing

1. Reading the image


2. Convert into gray scale
3. Histogram
4. Adust its intensity
5. Adjust into Black-white

You might also like