SlideShare a Scribd company logo
Do you speak MATLAB!
MathWorks®
MATLAB®
R2012a (7.14)
MATLAB
Introducing MATLAB – Language of technical computing 2
Is an integrated technical computing
environment that combines numeric computation, advanced
graphics and visualization, and a high-level programming language.
The MathWorks, Inc.
High-level language of technical computing
Development environment for engineers, scientists
Interactive tools for design, problem solving
Mathematical function libraries
Graphics and data visualization tools
Custom GUIs
External Interfaces: C, C++, Fortran, Java, COM, Excel, .NET
MATLAB product family
Toolboxes: Collections of specialized Functions
Graphics
2D Graphics
3D Graphics
Color & Lighting
Animation
Image, Audio & Video
Computations
Linear Algebra
Data Analysis
Polynomials
Interpolations
Solutions of ODE
External Interfaces
C
C++
JAVA
.net
Micorosoft Excel
Parallel Computing
Math, Statistics, and Optimization
Control System Design and Analysis
Signal Processing and Communications
Image Processing and Computer Vision
Test and Measurement
Built-in Functions
User-written Functions
MATLAB
Computational Finance
Computational Biology
Code Generation and Verification
Application Deployment
Database Connectivity and Reporting
MATLAB Programming
Language
Parallel Computing Toolbox
MATLAB Distributed Computing Server
Parallel Computing Symbolic Math Toolbox
Partial Differential Equation Toolbox
Statistics Toolbox
Curve Fitting Toolbox
Optimization Toolbox
Global Optimization Toolbox
Neural Network Toolbox
Model-Based Calibration Toolbox
Math, Statistics, and Optimization
Control System Toolbox
System Identification Toolbox
Fuzzy Logic Toolbox
Robust Control Toolbox
Model Predictive Control Toolbox
Aerospace Toolbox
Control System Design and Analysis Signal Processing Toolbox
DSP System Toolbox
Communications System Toolbox
Wavelet Toolbox
Fixed-Point Toolbox
RF Toolbox
Phased Array System Toolbox
Signal Processing and Communications
Image Processing Toolbox
Computer Vision System Toolbox
Image Acquisition Toolbox
Mapping Toolbox
Image Processing and Computer Vision
Data Acquisition Toolbox
Instrument Control Toolbox
Image Acquisition Toolbox
OPC Toolbox
Vehicle Network Toolbox
Test and Measurement
Financial Toolbox
Econometrics Toolbox
Datafeed Toolbox
Database Toolbox
Computational Finance
Spreadsheet Link EX (for Microsoft Excel)
Fixed-Income Toolbox
Financial Derivatives Toolbox
Bioinformatics Toolbox
SimBiology
Computational Biology
MATLAB Coder
HDL Coder
HDL Verifier
Filter Design HDL Coder
Code Generation and Verification
MATLAB Compiler
MATLAB Builder NE (for Microsoft .NET Framework)
MATLAB Builder JA (for Java language)
MATLAB Builder EX (for Microsoft Excel)
Spreadsheet Link EX (for Microsoft Excel)
Application Deployment
Database Toolbox
MATLAB Report Generator
Database Connectivity and Reporting
Introducing MATLAB – Language of technical computing 3
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
4
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
5
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Conditional control statements
Loop control statements
Functions – creating & executing a function file
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
6
Conditional control statements
Loop control statements
The main window characterized by the MATLAB command prompt (>>)
Command Window
This is where you write, edit, create, and save your own script or programs in files called
m-files.
Editor Window
This is where all your files from the current directory are listed.
Current Directory
All commands typed on MATLAB prompt in the command window get recorded, even
across multiple session in this window.
Command History
This subwindow lists all variables that you have generated so far along with there type
and size.
Workspace
MATLAB - Desktop
Minimal MATLAB 7
MATLAB - Desktop
The main window characterized by the MATLAB command prompt (>>)
Help Window
Minimal MATLAB 8
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
9
Conditional control statements
Loop control statements
Basic Data and Variables
Computing with MATLAB
Class
Variable
Size
Value
Minimal MATLAB 10
Basic Data and Variables
Computing with MATLAB
Multidimensional Array
[full or sparse]
Scalar

logical
ab
char
{ }
cell struct
function
handle (@)
numeric
int8, uint8,
int16, unit16,
int32, unit32,
int64, unit64
single double
Minimal MATLAB 11
Arithmetic Operator &
Their Precedence
Computing with MATLAB
Operations Operators Examples
Addition
Subtraction
Multiplication
Right Division
Left Division
Exponentiation
+
−
*
/

^
>> 𝟓 + 𝟑
>> 𝟓 − 𝟑
>> 𝟓 ∗ 𝟑
>> 𝟓/𝟑
>> 𝟓𝟑 = 𝟑/𝟓
>> 𝟓^𝟑 (means 𝟓𝟑
= 𝟏𝟐𝟓)
Precedence Order Operators
1
2
3
4
Parentheses ( ). For nested parentheses, the innermost
are executed first.
Exponentiation, ^
Multiplication, *; Division, /,
Addition, +; Subtraction, -
help precedence
Minimal MATLAB 12
Computing with MATLAB
Mathematical Functions
Trigonometry
sind
cosd
tand
cotd
secd
cscd
Degree
sin
cos
tan
cot
sec
csc
sinh
cosh
tanh
coth
sech
csch
asin
acos
atan
acot
asec
acsc
Basic Hyperbolic Inverse
Radian
Basic
Exponential
exp
log
log10
log2
sqrt
Complex
abs
conj
imag
real
angle
Matrix
det
trace
rank
inv
expm
sqrtm
Discrete Math
factorial
gcd
lcm
primes
help <type function name>
Minimal MATLAB 13
Predefined Variables and
Keywords
ans
pi
eps
inf
i,j
NaN
A variable that has the value of the last expression that was not assigned to a
specific variable
The number π.
The smallest difference between two numbers. Equal to 2^(–52), which is
approximately 2.2204e–016.
Used for infinity.
Defined as −1, which is: 0 + 1.0000i.
Stands for Not-a-Number. Used when MATLAB cannot determine a valid
numeric value. Example: 0/0.
Predefined Variables
break case catch classdef continue else elseif
end for function global if otherwise parfor
persistent return spmd switch try while
Keywords
iskeyword
help <Predefined Variable Name>
Computing with MATLAB
Minimal MATLAB 14
Managing Variables
clear
clear x y z
clear all
who
whos
Clears the workspace, all variables are removed from the memory
Clears only variables x, y, and z
Clears all variables and functions from workspace
Lists variables currently in the workspace
Lists variables currently in the workspace with their sizes together
with information about their bytes and class
Command Outcome
Computing with MATLAB
Minimal MATLAB 15
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
16
Conditional control statements
Loop control statements
Overview
Array
5
5
7
4
5 7 4
5 10 56
6 4 6
7 78 86
Scalar of 1 X 1 Row Vector of 1 X 3 Column vector of 3 X 1
One Dimensional
Matrix of 3 X 3
5 10 56 85 23
6 4 6 23 2
7 78 86 53 6
5 14 12 10 56
6 10 504 4 6
89 0
Two Dimensional
Matrix of 3 X 5
5 10 56 85 23
6 4 6 23 2
7 78 86 53 6
5 14 12 10 56
6
0
5 14 12 10 56
89
0
Three Dimensional
Matrix of 3 X 5
Minimal MATLAB 17
Creation
Array
One Dimensional Array
variable_name = [ type vector elements ]
Minimal MATLAB 18
Two Dimensional Array
variable_name = [1st row elements; 2nd row elements; 3rd row
elements; ... ; last row elements]
 from a known list of numbers
 with constant spacing by specifying the first term, the spacing, and the
last term
Known lists of numbers
Array
Minimal MATLAB 19
Creation
Creating a vector with constant spacing by specifying the
first term, the spacing, and the last term:
variable_name = [m:q:n]
or
variable_name = m:q:n
m = first term
q = spacing
n = last term
: (colon operator)
Constant spacing
Creating a vector with linear (equal) spacing by specifying
the first and last terms, and the number of terms:
variable_name = linspace(xi, xf, n)
xi = first element
xf = Last element
n = number of elements
linspace
Constant spacing
Array
Minimal MATLAB 20
Array Operators
+ Addition
- Subtraction
.* Element-by-element multiplication
./ Element-by-element division
. Element-by-element left division
.^ Element-by-element power
‘ Transpose
Operations Operation
𝐴 =
1 3
4 2
𝐵 =
2 3
5 7
𝐶 = 𝐴.∗ 𝐵 =
2 9
20 14
𝐶 =
1 × 2 3 × 3
4 × 5 2 × 7
Data Manipulation
Array
Minimal MATLAB 21
Addressing - Extraction (Subset)
Addressing an element(s) individually or in subgroups:
 To redefine only some of the elements,
 When specific elements are to be used in calculations,
 When a subgroup of the elements is used to define a new variable.
Array
Minimal MATLAB 22
Address vector
>> ve = [35 46 78 23 5 14 81 3 55]
ve =
35 46 78 23 5 14 81 3 55
1 2 3 4 5 6 7 8 9 position or index of element
Data Manipulation
Array
Minimal MATLAB 23
Address matrix )
3 11 6 5
4 7 10 2
13 9 0 8
MAT =
(1,1) (1,2) (1,3) (1,4)
(2,1) (2,2) (2,3) (2,4)
(3,1) (3,2) (3,3) (3,4)
3 11 6 5
4 7 10 2
13 9 0 8
MAT =
Data Manipulation
Array
Minimal MATLAB 24
Addressing vector : (colon operator)
Data Manipulation
Addressing matrix : (colon operator)
A(:,n) Refers to the elements in all the rows of column n of the matrix A.
A(n,:) Refers to the elements in all the columns of row n of the matrix A.
A(:,m:n) Refers to the elements in all the rows between columns m and n
of the matrix A.
A(m:n,:) Refers to the elements in all the columns between rows m and n
of the matrix A.
A(m:n,p:q)
Refers to the elements in rows m through n and columns p
through q of the matrix A.
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
25
Conditional control statements
Loop control statements
Creation
Plotting
Minimal MATLAB 26
Example
Damped Oscillation equation: 𝒚 = 𝒆−𝒂𝒕 𝐜𝐨𝐬 (𝒃𝒕)
Creation
Plotting
Minimal MATLAB 27
Example
Damped Oscillation equation: 𝒚 = 𝒆−𝒂𝒕 𝐜𝐨𝐬 (𝒃𝒕)
a = 0.1; b = 1;
t = 0:0.1:20;
y = exp(-a*t).*cos(b*t);
plot(t,y)
grid on;
xlabel('Time in second');
ylabel('Response in mm');
title('Damped Oscillation');
legend('a = 0.1,b = 1)');
1-
2-
3-
4-
5-
6-
7-
8-
9-
Creation
Plotting
Minimal MATLAB 28
Overview
ylabel xlabel
title
legend
Graphing
Plotting
Minimal MATLAB 29
Plot function plot(x,y)
where the variables x and y are vector and must be of same size i.e the number of
elements should be equal.
x=[1 2 3 5 7 7.5 8 10];
y=[2 6.5 7 7 5.5 4 6 8];
plot(x,y)
Graphing
Plotting
Minimal MATLAB 30
Plot function
plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)
Line specifiers are optional and can be used to define the style and color of the
line and the type of markers (if markers are desired).
Line specifiers
solid (default)
dashed
dotted
dash-dot
Line Style Specifier
-
--
:
-.
red
green
blue
cyan
Line color Specifier
r
g
b
c
magenta
yellow
black
white
Line color Specifier
m
y
k
w
Graphing
Plotting
Minimal MATLAB 31
Plot function
plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)
Line specifiers are optional and can be used to define the style and color of the
line and the type of markers (if markers are desired).
Line specifiers
plus sign
circle
asterisk
point
cross
triangle (pointed up)
triangle (pointed down)
Marker type Specifier
+
o
*
.
×
^
v
square
diamond
five pointed star
six pointed star
triangle (pointed left)
triangle (pointed right)
Marker type Specifier
s
d
p
h
<
>
Graphing
Plotting
Minimal MATLAB 32
Plot function
plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue)
To specify the thickness of the line, the size of the marker, and the colors of the marker’s
edge line and fill
Property Name
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
33
Conditional control statements
Loop control statements
Creation
Script
Minimal MATLAB 34
Overview
Sequence of MATLAB statements in file
Script
A script file is an external file that contains a sequence of MATLAB statements. Script
files have a filename extension of .m.
Basics
Script
Minimal MATLAB 35
variable_name = input(‘prompt message’)
Accepting input from user
Displaying output to user
disp(name of a variable)
disp(‘text as string’)
Saving script file
Creating script file
Executing script file
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
36
Conditional control statements
Loop control statements
Creation
Script
Minimal MATLAB 37
Conditional Statement
Conditional expression consisting of relational and/or logical operators.
Operations Operators
Less than
Greater than
Less than or equal to
Greater than or equal to
Equal to
Not Equal to
<
>
<=
>=
==
~=
Relational Operators
Operations Operators
And
Or
Not
&&
||
~
Logical Operators
Creation
Script
Minimal MATLAB 38
Example
𝑔 𝑡 =
0, 𝑡 < −2
−4 − 2𝑡, −2 < 𝑡 < 0
−4 − 3𝑡, 0 < 𝑡 < 4
16 − 2𝑡, 4 < 𝑡 < 8
0, 𝑡 > 8
Plot
g1
g2
g3
t = linspace(-5,10);
g1 = -4 - 2*t;
g2 = -4 + 3*t;
g3 = 16 - 2*t;
g = g1.*(-2<t & t<=0)...
+ g2.*(0<t & t<=4)...
+ g3.*(4<t & t<=8);
plot(t,g)
1-
2-
3-
4-
5-
6-
7-
g1
g2
g3
if/elseif/else Statement
Script
Minimal MATLAB 39
if
statement
Statement
Group 1
False
True
End
Statement
Group 2
if expression
statements
elseif expression
statements
else
statements
end
Creation
Script
Minimal MATLAB 40
Switch Statement
False
True
Flowchart
match
case, k
case
end
False
case
statement, k
True
switch switch_expression
case case_expression
statements
case case_expression
statements
:
otherwise
statements
end
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
41
Conditional control statements
Loop control statements
Loop control statements
Script
Minimal MATLAB 42
for (Iterative Loop)
while (Conditional Loop)
continue, break
for index = start:increment:end
statements
end
while expression
statements
end
Agenda
Introducing MATLAB – Language of technical computing
Minimal MATLAB
MATLAB Desktop
Computing with MATLAB
Array – creation & working
Plotting – creating & visualizing
Automating commands – creating, saving & executing script file
Functions – creating & executing a function file
43
Conditional control statements
Loop control statements
Creation
Function
Minimal MATLAB 44
Overview
SYSTEM
[Mathematical model of
Physical Phenomenon]
(function file)
Set of inputs Set of outputs
1
2
3
m
1
2
3
n
[System]
Electrical Networks
Communication System
Control System
Thermodynamic System
Computer system, etc
[Input variables]
current, voltage,
power, energy,
temperature,
data
[Output variables]
current, voltage,
power, energy,
temperature,
Processed data
function [out1, out2, ...] = func_name(in1, in2, ...)
declares the function func_name, and its inputs and outputs
Creation
Function
Minimal MATLAB 45
Example
𝐻 =
𝑦
𝑥
=
1
1 + (𝜔𝑅𝐶)2
Black Box
X Y
function H = lp(R,C)
w = logspace(-2,6);
H = 1./sqrt(1 + (w*R*C).^2);
semilogx(w,H)
xlabel('Angular frquency, w (rad/s)');
ylabel('System Response');
title('Low-Pass frequency response');
1-
2-
3-
4-
5-
6-
Source: MATLAB An Introduction with Applications, Amos Gilat, 4e
Creation
Function
Minimal MATLAB 46
Example
Creation
Function
Minimal MATLAB 47
Example
Black Box
𝑇
𝑇𝑑
𝑇𝑤
𝐵𝑃
𝑅𝐻
𝑅𝐻 = 100
𝑒
𝑒𝑠
𝑇𝑑 =
243.5 ln(
𝑒
6.112
)
17.67 − ln(
𝑒
6.112
)
𝑇𝑑, dew point temperature °𝐶
𝑇, dry-bulb temperature °𝐶
𝑇𝑤, wet-bulb temperature °𝐶
𝐵𝑃, barometric temperature in millibars
𝑅𝐻, relative humidity in %
𝑃𝑠 = 6.112 exp
17.67𝑇
𝑇 + 243.5
𝑃𝑤 = 6.112 exp
17.67𝑇𝑤
𝑇𝑤 + 243.5
𝑒 = 𝑒𝑤 − 𝐵𝑃 𝑇 − 𝑇𝑤 0.00066(1 + 0.00115𝑇𝑤)
Source: MATLAB An Introduction with Applications, Amos Gilat, 4e
Creation
Function
Minimal MATLAB 48
Example
function [Td, RH] = DewptRhum(T,Tw,BP)
es = 6.112*exp((17.67*T)/(T + 243.5));
ew = 6.112*exp((17.67*Tw)/(Tw + 243.5));
e = ew - BP*(T - Tw)*0.00066*(1 + 0.00115*Tw);
RH = 100*(e/es);
Td = (243.5*log(e/6.112))/(17.67 - log(e/6.112));
1-
2-
3-
4-
5-
𝑇 = 25°𝐶, 𝑇𝑤 = 19°𝐶, 𝐵𝑃 = 985 𝑚𝑖𝑙𝑙𝑖𝑏𝑎𝑟
Calculate 𝑻𝒅 =? , 𝑹𝑯 =?
𝑇 = 36°𝐶, 𝑇𝑤 = 31°𝐶, 𝐵𝑃 = 1020 𝑚𝑖𝑙𝑙𝑖𝑏𝑎𝑟
BEFORE
LEAVING
More on MATLAB
1. MATLAB Tutorials
2. Demo and Webinars
3. Documentations
4. MATLAB Central (User Community)
www.mathworks.com
Reference
1. Getting started with MATLAB, A quick introduction for scientists and engineers,
Rudra Pratap, Indian edition
2. MATLAB An Introduction with Applications, Amos Gilat, 4e
3. Matlab - A Practical Introduction to Programming and Problem Solving, Stormy
Attaway, 2e
4. Essential MATLAB for Engineers and Scientists, Brian D. Hahn & Daniel T.
Valentine
5. A Guide to MATLAB for Beginners and Experienced Users, Hunt Lipsman &
Rosenberg
THANKS
We speak MATLAB!
ASHISH MESHRAM
meetashish85@gmail.com
www.facebook.com/ashishmeet

More Related Content

PPSX
Matlab basic and image
PDF
MATLAB Programming
PDF
MATLAB INTRODUCTION
PPTX
Introduction to matlab lecture 1 of 4
PPTX
PDF
Introduction to matlab
PDF
Introduction to MATLAB
PPT
Matlab anilkumar
Matlab basic and image
MATLAB Programming
MATLAB INTRODUCTION
Introduction to matlab lecture 1 of 4
Introduction to matlab
Introduction to MATLAB
Matlab anilkumar

Similar to matlab-130408153714-phpapp02_lab123.ppsx (20)

PPTX
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
PPT
Matlab Introduction for beginners_i .ppt
PPT
Matlab_Introduction_by_Michael_Medvinsky.ppt
PPT
MatlabIntroduction presentation xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
Lines and planes in space
PPT
Matlab practical and lab session
PDF
An Introduction to MATLAB with Worked Examples
PPTX
Matlab - Introduction and Basics
PPT
MatlabIntro1234.ppt.....................
PDF
PPTX
Introduction to matlab
PDF
Malab tutorial
PPT
Matlab introduction
PPT
Matlab introduction
PDF
PPTX
Raushan's MATLB PPT..pptx
PPT
WIDI ediot autis dongok part 2.ediot lu lembot lu
PPT
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
PDF
lecture #1 & 2....education....matlab...helpful
PPT
Introduction to Matlab.ppt
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
Matlab Introduction for beginners_i .ppt
Matlab_Introduction_by_Michael_Medvinsky.ppt
MatlabIntroduction presentation xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Lines and planes in space
Matlab practical and lab session
An Introduction to MATLAB with Worked Examples
Matlab - Introduction and Basics
MatlabIntro1234.ppt.....................
Introduction to matlab
Malab tutorial
Matlab introduction
Matlab introduction
Raushan's MATLB PPT..pptx
WIDI ediot autis dongok part 2.ediot lu lembot lu
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
lecture #1 & 2....education....matlab...helpful
Introduction to Matlab.ppt
Ad

More from lekhacce (20)

PPTX
CSS Selectors in web design program.pptx
PPT
cascading style sheet in web design .ppt
PPTX
Introduction to Webdesign .pptx
PPTX
Introduction to HTML .pptx
PPTX
Informationa Retrieval Techniques .pptx.pptx
PPTX
Informationa Retrieval Techniques .pptx
PPTX
Information Retrieval slides_chap02.pptx
PPTX
Information Retrieval slides_chap01.pptx
PPT
Extended Markup Basic Introduction .ppt
PPT
modes-of-operation in cryptography. .ppt
PPTX
OLAP operations in Data warehousing.pptx
PPTX
Introduction to HTML language Web design.pptx
PPTX
HTML_TABLES,FORMS,FRAME markup lang.pptx
PPTX
javascript client side scripting la.pptx
PPTX
webdevelopment_6132030-lva1-app6891.pptx
PPT
1_chapter one Java content materials.ppt
PPTX
Information RetrievalsT_I_materials.pptx
PDF
Information_Retrievals Unit_3_chap09.pdf
PDF
slides_chap02.pdf
PPTX
AES.pptx
CSS Selectors in web design program.pptx
cascading style sheet in web design .ppt
Introduction to Webdesign .pptx
Introduction to HTML .pptx
Informationa Retrieval Techniques .pptx.pptx
Informationa Retrieval Techniques .pptx
Information Retrieval slides_chap02.pptx
Information Retrieval slides_chap01.pptx
Extended Markup Basic Introduction .ppt
modes-of-operation in cryptography. .ppt
OLAP operations in Data warehousing.pptx
Introduction to HTML language Web design.pptx
HTML_TABLES,FORMS,FRAME markup lang.pptx
javascript client side scripting la.pptx
webdevelopment_6132030-lva1-app6891.pptx
1_chapter one Java content materials.ppt
Information RetrievalsT_I_materials.pptx
Information_Retrievals Unit_3_chap09.pdf
slides_chap02.pdf
AES.pptx
Ad

Recently uploaded (20)

PDF
Well-logging-methods_new................
PDF
Digital Logic Computer Design lecture notes
PPTX
Lecture Notes Electrical Wiring System Components
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
DOCX
573137875-Attendance-Management-System-original
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Geodesy 1.pptx...............................................
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Well-logging-methods_new................
Digital Logic Computer Design lecture notes
Lecture Notes Electrical Wiring System Components
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
573137875-Attendance-Management-System-original
Operating System & Kernel Study Guide-1 - converted.pdf
additive manufacturing of ss316l using mig welding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Mechanical Engineering MATERIALS Selection
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Internet of Things (IOT) - A guide to understanding
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Geodesy 1.pptx...............................................
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

matlab-130408153714-phpapp02_lab123.ppsx

  • 1. Do you speak MATLAB!
  • 3. MATLAB Introducing MATLAB – Language of technical computing 2 Is an integrated technical computing environment that combines numeric computation, advanced graphics and visualization, and a high-level programming language. The MathWorks, Inc. High-level language of technical computing Development environment for engineers, scientists Interactive tools for design, problem solving Mathematical function libraries Graphics and data visualization tools Custom GUIs External Interfaces: C, C++, Fortran, Java, COM, Excel, .NET
  • 4. MATLAB product family Toolboxes: Collections of specialized Functions Graphics 2D Graphics 3D Graphics Color & Lighting Animation Image, Audio & Video Computations Linear Algebra Data Analysis Polynomials Interpolations Solutions of ODE External Interfaces C C++ JAVA .net Micorosoft Excel Parallel Computing Math, Statistics, and Optimization Control System Design and Analysis Signal Processing and Communications Image Processing and Computer Vision Test and Measurement Built-in Functions User-written Functions MATLAB Computational Finance Computational Biology Code Generation and Verification Application Deployment Database Connectivity and Reporting MATLAB Programming Language Parallel Computing Toolbox MATLAB Distributed Computing Server Parallel Computing Symbolic Math Toolbox Partial Differential Equation Toolbox Statistics Toolbox Curve Fitting Toolbox Optimization Toolbox Global Optimization Toolbox Neural Network Toolbox Model-Based Calibration Toolbox Math, Statistics, and Optimization Control System Toolbox System Identification Toolbox Fuzzy Logic Toolbox Robust Control Toolbox Model Predictive Control Toolbox Aerospace Toolbox Control System Design and Analysis Signal Processing Toolbox DSP System Toolbox Communications System Toolbox Wavelet Toolbox Fixed-Point Toolbox RF Toolbox Phased Array System Toolbox Signal Processing and Communications Image Processing Toolbox Computer Vision System Toolbox Image Acquisition Toolbox Mapping Toolbox Image Processing and Computer Vision Data Acquisition Toolbox Instrument Control Toolbox Image Acquisition Toolbox OPC Toolbox Vehicle Network Toolbox Test and Measurement Financial Toolbox Econometrics Toolbox Datafeed Toolbox Database Toolbox Computational Finance Spreadsheet Link EX (for Microsoft Excel) Fixed-Income Toolbox Financial Derivatives Toolbox Bioinformatics Toolbox SimBiology Computational Biology MATLAB Coder HDL Coder HDL Verifier Filter Design HDL Coder Code Generation and Verification MATLAB Compiler MATLAB Builder NE (for Microsoft .NET Framework) MATLAB Builder JA (for Java language) MATLAB Builder EX (for Microsoft Excel) Spreadsheet Link EX (for Microsoft Excel) Application Deployment Database Toolbox MATLAB Report Generator Database Connectivity and Reporting Introducing MATLAB – Language of technical computing 3
  • 5. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB 4
  • 6. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB 5 Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Conditional control statements Loop control statements Functions – creating & executing a function file
  • 7. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 6 Conditional control statements Loop control statements
  • 8. The main window characterized by the MATLAB command prompt (>>) Command Window This is where you write, edit, create, and save your own script or programs in files called m-files. Editor Window This is where all your files from the current directory are listed. Current Directory All commands typed on MATLAB prompt in the command window get recorded, even across multiple session in this window. Command History This subwindow lists all variables that you have generated so far along with there type and size. Workspace MATLAB - Desktop Minimal MATLAB 7
  • 9. MATLAB - Desktop The main window characterized by the MATLAB command prompt (>>) Help Window Minimal MATLAB 8
  • 10. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 9 Conditional control statements Loop control statements
  • 11. Basic Data and Variables Computing with MATLAB Class Variable Size Value Minimal MATLAB 10
  • 12. Basic Data and Variables Computing with MATLAB Multidimensional Array [full or sparse] Scalar  logical ab char { } cell struct function handle (@) numeric int8, uint8, int16, unit16, int32, unit32, int64, unit64 single double Minimal MATLAB 11
  • 13. Arithmetic Operator & Their Precedence Computing with MATLAB Operations Operators Examples Addition Subtraction Multiplication Right Division Left Division Exponentiation + − * / ^ >> 𝟓 + 𝟑 >> 𝟓 − 𝟑 >> 𝟓 ∗ 𝟑 >> 𝟓/𝟑 >> 𝟓𝟑 = 𝟑/𝟓 >> 𝟓^𝟑 (means 𝟓𝟑 = 𝟏𝟐𝟓) Precedence Order Operators 1 2 3 4 Parentheses ( ). For nested parentheses, the innermost are executed first. Exponentiation, ^ Multiplication, *; Division, /, Addition, +; Subtraction, - help precedence Minimal MATLAB 12
  • 14. Computing with MATLAB Mathematical Functions Trigonometry sind cosd tand cotd secd cscd Degree sin cos tan cot sec csc sinh cosh tanh coth sech csch asin acos atan acot asec acsc Basic Hyperbolic Inverse Radian Basic Exponential exp log log10 log2 sqrt Complex abs conj imag real angle Matrix det trace rank inv expm sqrtm Discrete Math factorial gcd lcm primes help <type function name> Minimal MATLAB 13
  • 15. Predefined Variables and Keywords ans pi eps inf i,j NaN A variable that has the value of the last expression that was not assigned to a specific variable The number π. The smallest difference between two numbers. Equal to 2^(–52), which is approximately 2.2204e–016. Used for infinity. Defined as −1, which is: 0 + 1.0000i. Stands for Not-a-Number. Used when MATLAB cannot determine a valid numeric value. Example: 0/0. Predefined Variables break case catch classdef continue else elseif end for function global if otherwise parfor persistent return spmd switch try while Keywords iskeyword help <Predefined Variable Name> Computing with MATLAB Minimal MATLAB 14
  • 16. Managing Variables clear clear x y z clear all who whos Clears the workspace, all variables are removed from the memory Clears only variables x, y, and z Clears all variables and functions from workspace Lists variables currently in the workspace Lists variables currently in the workspace with their sizes together with information about their bytes and class Command Outcome Computing with MATLAB Minimal MATLAB 15
  • 17. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 16 Conditional control statements Loop control statements
  • 18. Overview Array 5 5 7 4 5 7 4 5 10 56 6 4 6 7 78 86 Scalar of 1 X 1 Row Vector of 1 X 3 Column vector of 3 X 1 One Dimensional Matrix of 3 X 3 5 10 56 85 23 6 4 6 23 2 7 78 86 53 6 5 14 12 10 56 6 10 504 4 6 89 0 Two Dimensional Matrix of 3 X 5 5 10 56 85 23 6 4 6 23 2 7 78 86 53 6 5 14 12 10 56 6 0 5 14 12 10 56 89 0 Three Dimensional Matrix of 3 X 5 Minimal MATLAB 17
  • 19. Creation Array One Dimensional Array variable_name = [ type vector elements ] Minimal MATLAB 18 Two Dimensional Array variable_name = [1st row elements; 2nd row elements; 3rd row elements; ... ; last row elements]  from a known list of numbers  with constant spacing by specifying the first term, the spacing, and the last term Known lists of numbers
  • 20. Array Minimal MATLAB 19 Creation Creating a vector with constant spacing by specifying the first term, the spacing, and the last term: variable_name = [m:q:n] or variable_name = m:q:n m = first term q = spacing n = last term : (colon operator) Constant spacing Creating a vector with linear (equal) spacing by specifying the first and last terms, and the number of terms: variable_name = linspace(xi, xf, n) xi = first element xf = Last element n = number of elements linspace Constant spacing
  • 21. Array Minimal MATLAB 20 Array Operators + Addition - Subtraction .* Element-by-element multiplication ./ Element-by-element division . Element-by-element left division .^ Element-by-element power ‘ Transpose Operations Operation 𝐴 = 1 3 4 2 𝐵 = 2 3 5 7 𝐶 = 𝐴.∗ 𝐵 = 2 9 20 14 𝐶 = 1 × 2 3 × 3 4 × 5 2 × 7
  • 22. Data Manipulation Array Minimal MATLAB 21 Addressing - Extraction (Subset) Addressing an element(s) individually or in subgroups:  To redefine only some of the elements,  When specific elements are to be used in calculations,  When a subgroup of the elements is used to define a new variable.
  • 23. Array Minimal MATLAB 22 Address vector >> ve = [35 46 78 23 5 14 81 3 55] ve = 35 46 78 23 5 14 81 3 55 1 2 3 4 5 6 7 8 9 position or index of element Data Manipulation
  • 24. Array Minimal MATLAB 23 Address matrix ) 3 11 6 5 4 7 10 2 13 9 0 8 MAT = (1,1) (1,2) (1,3) (1,4) (2,1) (2,2) (2,3) (2,4) (3,1) (3,2) (3,3) (3,4) 3 11 6 5 4 7 10 2 13 9 0 8 MAT = Data Manipulation
  • 25. Array Minimal MATLAB 24 Addressing vector : (colon operator) Data Manipulation Addressing matrix : (colon operator) A(:,n) Refers to the elements in all the rows of column n of the matrix A. A(n,:) Refers to the elements in all the columns of row n of the matrix A. A(:,m:n) Refers to the elements in all the rows between columns m and n of the matrix A. A(m:n,:) Refers to the elements in all the columns between rows m and n of the matrix A. A(m:n,p:q) Refers to the elements in rows m through n and columns p through q of the matrix A.
  • 26. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 25 Conditional control statements Loop control statements
  • 27. Creation Plotting Minimal MATLAB 26 Example Damped Oscillation equation: 𝒚 = 𝒆−𝒂𝒕 𝐜𝐨𝐬 (𝒃𝒕)
  • 28. Creation Plotting Minimal MATLAB 27 Example Damped Oscillation equation: 𝒚 = 𝒆−𝒂𝒕 𝐜𝐨𝐬 (𝒃𝒕) a = 0.1; b = 1; t = 0:0.1:20; y = exp(-a*t).*cos(b*t); plot(t,y) grid on; xlabel('Time in second'); ylabel('Response in mm'); title('Damped Oscillation'); legend('a = 0.1,b = 1)'); 1- 2- 3- 4- 5- 6- 7- 8- 9-
  • 30. Graphing Plotting Minimal MATLAB 29 Plot function plot(x,y) where the variables x and y are vector and must be of same size i.e the number of elements should be equal. x=[1 2 3 5 7 7.5 8 10]; y=[2 6.5 7 7 5.5 4 6 8]; plot(x,y)
  • 31. Graphing Plotting Minimal MATLAB 30 Plot function plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue) Line specifiers are optional and can be used to define the style and color of the line and the type of markers (if markers are desired). Line specifiers solid (default) dashed dotted dash-dot Line Style Specifier - -- : -. red green blue cyan Line color Specifier r g b c magenta yellow black white Line color Specifier m y k w
  • 32. Graphing Plotting Minimal MATLAB 31 Plot function plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue) Line specifiers are optional and can be used to define the style and color of the line and the type of markers (if markers are desired). Line specifiers plus sign circle asterisk point cross triangle (pointed up) triangle (pointed down) Marker type Specifier + o * . × ^ v square diamond five pointed star six pointed star triangle (pointed left) triangle (pointed right) Marker type Specifier s d p h < >
  • 33. Graphing Plotting Minimal MATLAB 32 Plot function plot(x,y,‘line specifiers’,‘PropertyName’,PropertyValue) To specify the thickness of the line, the size of the marker, and the colors of the marker’s edge line and fill Property Name
  • 34. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 33 Conditional control statements Loop control statements
  • 35. Creation Script Minimal MATLAB 34 Overview Sequence of MATLAB statements in file Script A script file is an external file that contains a sequence of MATLAB statements. Script files have a filename extension of .m.
  • 36. Basics Script Minimal MATLAB 35 variable_name = input(‘prompt message’) Accepting input from user Displaying output to user disp(name of a variable) disp(‘text as string’) Saving script file Creating script file Executing script file
  • 37. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 36 Conditional control statements Loop control statements
  • 38. Creation Script Minimal MATLAB 37 Conditional Statement Conditional expression consisting of relational and/or logical operators. Operations Operators Less than Greater than Less than or equal to Greater than or equal to Equal to Not Equal to < > <= >= == ~= Relational Operators Operations Operators And Or Not && || ~ Logical Operators
  • 39. Creation Script Minimal MATLAB 38 Example 𝑔 𝑡 = 0, 𝑡 < −2 −4 − 2𝑡, −2 < 𝑡 < 0 −4 − 3𝑡, 0 < 𝑡 < 4 16 − 2𝑡, 4 < 𝑡 < 8 0, 𝑡 > 8 Plot g1 g2 g3 t = linspace(-5,10); g1 = -4 - 2*t; g2 = -4 + 3*t; g3 = 16 - 2*t; g = g1.*(-2<t & t<=0)... + g2.*(0<t & t<=4)... + g3.*(4<t & t<=8); plot(t,g) 1- 2- 3- 4- 5- 6- 7- g1 g2 g3
  • 40. if/elseif/else Statement Script Minimal MATLAB 39 if statement Statement Group 1 False True End Statement Group 2 if expression statements elseif expression statements else statements end
  • 41. Creation Script Minimal MATLAB 40 Switch Statement False True Flowchart match case, k case end False case statement, k True switch switch_expression case case_expression statements case case_expression statements : otherwise statements end
  • 42. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 41 Conditional control statements Loop control statements
  • 43. Loop control statements Script Minimal MATLAB 42 for (Iterative Loop) while (Conditional Loop) continue, break for index = start:increment:end statements end while expression statements end
  • 44. Agenda Introducing MATLAB – Language of technical computing Minimal MATLAB MATLAB Desktop Computing with MATLAB Array – creation & working Plotting – creating & visualizing Automating commands – creating, saving & executing script file Functions – creating & executing a function file 43 Conditional control statements Loop control statements
  • 45. Creation Function Minimal MATLAB 44 Overview SYSTEM [Mathematical model of Physical Phenomenon] (function file) Set of inputs Set of outputs 1 2 3 m 1 2 3 n [System] Electrical Networks Communication System Control System Thermodynamic System Computer system, etc [Input variables] current, voltage, power, energy, temperature, data [Output variables] current, voltage, power, energy, temperature, Processed data function [out1, out2, ...] = func_name(in1, in2, ...) declares the function func_name, and its inputs and outputs
  • 46. Creation Function Minimal MATLAB 45 Example 𝐻 = 𝑦 𝑥 = 1 1 + (𝜔𝑅𝐶)2 Black Box X Y function H = lp(R,C) w = logspace(-2,6); H = 1./sqrt(1 + (w*R*C).^2); semilogx(w,H) xlabel('Angular frquency, w (rad/s)'); ylabel('System Response'); title('Low-Pass frequency response'); 1- 2- 3- 4- 5- 6- Source: MATLAB An Introduction with Applications, Amos Gilat, 4e
  • 48. Creation Function Minimal MATLAB 47 Example Black Box 𝑇 𝑇𝑑 𝑇𝑤 𝐵𝑃 𝑅𝐻 𝑅𝐻 = 100 𝑒 𝑒𝑠 𝑇𝑑 = 243.5 ln( 𝑒 6.112 ) 17.67 − ln( 𝑒 6.112 ) 𝑇𝑑, dew point temperature °𝐶 𝑇, dry-bulb temperature °𝐶 𝑇𝑤, wet-bulb temperature °𝐶 𝐵𝑃, barometric temperature in millibars 𝑅𝐻, relative humidity in % 𝑃𝑠 = 6.112 exp 17.67𝑇 𝑇 + 243.5 𝑃𝑤 = 6.112 exp 17.67𝑇𝑤 𝑇𝑤 + 243.5 𝑒 = 𝑒𝑤 − 𝐵𝑃 𝑇 − 𝑇𝑤 0.00066(1 + 0.00115𝑇𝑤) Source: MATLAB An Introduction with Applications, Amos Gilat, 4e
  • 49. Creation Function Minimal MATLAB 48 Example function [Td, RH] = DewptRhum(T,Tw,BP) es = 6.112*exp((17.67*T)/(T + 243.5)); ew = 6.112*exp((17.67*Tw)/(Tw + 243.5)); e = ew - BP*(T - Tw)*0.00066*(1 + 0.00115*Tw); RH = 100*(e/es); Td = (243.5*log(e/6.112))/(17.67 - log(e/6.112)); 1- 2- 3- 4- 5- 𝑇 = 25°𝐶, 𝑇𝑤 = 19°𝐶, 𝐵𝑃 = 985 𝑚𝑖𝑙𝑙𝑖𝑏𝑎𝑟 Calculate 𝑻𝒅 =? , 𝑹𝑯 =? 𝑇 = 36°𝐶, 𝑇𝑤 = 31°𝐶, 𝐵𝑃 = 1020 𝑚𝑖𝑙𝑙𝑖𝑏𝑎𝑟
  • 51. More on MATLAB 1. MATLAB Tutorials 2. Demo and Webinars 3. Documentations 4. MATLAB Central (User Community) www.mathworks.com
  • 52. Reference 1. Getting started with MATLAB, A quick introduction for scientists and engineers, Rudra Pratap, Indian edition 2. MATLAB An Introduction with Applications, Amos Gilat, 4e 3. Matlab - A Practical Introduction to Programming and Problem Solving, Stormy Attaway, 2e 4. Essential MATLAB for Engineers and Scientists, Brian D. Hahn & Daniel T. Valentine 5. A Guide to MATLAB for Beginners and Experienced Users, Hunt Lipsman & Rosenberg
  • 53. THANKS We speak MATLAB! ASHISH MESHRAM meetashish85@gmail.com www.facebook.com/ashishmeet