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

Introduction to

Programming in Matlab

with Applications (For Beginners)


by
Raza Ali Shah (PhD student ICT, SET)
Day 1 Day2 Day 3
z Introductions z Script files z Linear
algebra
z Variables z Functions
z Polynomials
z Operations z Conditional
statements z Optimization
z Plotting z Loops in Matlab z Debugging
z Break / continue z Application
specific
Examples

Raza Ali Shah, ICT/SET/AIT 2


Starting Matlab
z Introduction to Matlab windows
z Customization
• Preferences
• Layouts
z Working in Command Window
z Explore Matlab demos
z Some Useful Commands

Raza Ali Shah, ICT/SET/AIT 3


Raza Ali Shah, ICT/SET/AIT 4
Customization
z File > Preferences
• Allows you personalize your MATLAB experience

Raza Ali Shah, ICT/SET/AIT 5


Introduction to Matlab windows

Raza Ali Shah, ICT/SET/AIT 6


Calculations - Display formats
z >> 101*(3+ 3^2 + 27^(1/3) )/7 % display format = short
z ans =
z 216.4286
z >> ans % display format = long
z ans =
z 2.164285714285714e+002
z >> ans % display format = short e
z ans =
z 2.1643e+002
z >> ans % display format = long e
z ans =
z 2.164285714285714e+002
z >> ans % display format = short g
z ans =
z 216.43

Raza Ali Shah, ICT/SET/AIT 7


Display formats

Raza Ali Shah, ICT/SET/AIT 8


Some Built-in math functions

Raza Ali Shah, ICT/SET/AIT 9


Rounding Functions

Raza Ali Shah, ICT/SET/AIT 10


Variables
z To create a variable, simply assign a value to a name:
• >> var1=3.14
• >> c = ‘2*3 =6’
• >> d =2*3
• >> mystring = ‘Hello World’
z Built-in variables

Raza Ali Shah, ICT/SET/AIT 11


Scalars

Raza Ali Shah, ICT/SET/AIT 12


Arrays

Raza Ali Shah, ICT/SET/AIT 13


Row Vectors

Raza Ali Shah, ICT/SET/AIT 14


Column Vectors

Raza Ali Shah, ICT/SET/AIT 15


Matrices

Raza Ali Shah, ICT/SET/AIT 16


save/ clear/ load

Raza Ali Shah, ICT/SET/AIT 17


Conversing with MATLAB
z who / whos
• MATLAB replies with the variables in your workspace
z what
• MATLAB replies with the current directory and
MATLAB files in the directory
z help
• The most important function for learning MATLAB on
your own
z why

Raza Ali Shah, ICT/SET/AIT 18


help / doc

Raza Ali Shah, ICT/SET/AIT 19


Exercise

Raza Ali Shah, ICT/SET/AIT 20

You might also like