SlideShare a Scribd company logo
INTRODUCTION
MATLAB
By: Prof. Ganesh Ingle
Session Objective
MATLAB INTRODUCTION
IDE ,COMMANDS ,RESULTS ,M FILE
CONDITIONAL STATEMENTS (if,switch)
LOOPING STATEMENTS, ARRAYS ,FILE HANDLING
SUMMARY
MATLAB Applications
1. Communication engineering
2. AI,ML,DL
3. Image processing
4. Optimization
5. Data access ,analysis and visualization
6. Programming and algorithm designing
7. Performance analysis of algorithms
8. Simulink
MATLAB Commands
1. date
2. clock
3. ver
4. whos
5. what(files in current dir)
6. clc
7. clear
8. diary filename
9. diary off
10. diary on
11. path
12. editpath GUI ,home,set path
13.! DOS command
14. exit
MATLAB Operators/Symbols/Functions
1. +
2. -
3. *
4. /
5. ^
6. =
7. ==
8. pi
9. vpa (digit precision)
10. %
11. ;
12. : range
13.randn() %10,
1:1:10;
14. Ctrl+c
15. ceil
16. floor
17. sqrt
18. Matrix (+,-,*)
19. ‘.’ operator
20. eye
21. zeros(5)
22. ` transpose
23. ones(6)
MATLAB Operators/Symbols/Functions
24. imread()
25. imshow
26. disp()
27. input()
28. factorial()
29. length(a)
30. size(a)
31. fprintf()-only o/p
32. sprintf()-o/p with save in workspace
33. format rat/ long /hex /shortEng/logEng
34. de2bi, d=(1:10)’; b=de2bi(d); [d,b]
35. decimalToBinaryVector(x);MSB,LSB
MATLAB Operators/Symbols/Functions
36. All trigonometric values and error o/p
37. cosd(),sind()
38. All hyperbolic trigonometric values
39. mod(x,y)
40. log(x) %natural log
41. log10(x)
MATLAB Variables and Data types
Data types
Logical Char Numeric
Int 8 unint 8
Int 16 unint 16
Int 32 unint 32
Int 64 unint 64
Single Double
Structure Function Handle
Typing Mathematical Expression
1)
R1=
−𝑏+ 𝑏2−4𝑎𝑐
2𝑎
R2=
−𝑏± 𝑏
2
−4𝑎𝑐
2𝑎
2)
R1= 𝑎2 + 𝑏2
e-0.2t cos 2t
3)
E=mc2
Y=1 +
𝑛𝑥
1!
+
𝑛 𝑛−1 𝑥2
2!
MATLAB Code File
1. File name should not start with number
2. No Space in the file name
3. No library function name
4. No use of keywords reserved by MATALAB
MATLAB Searching Mechanism
1. Workspace
2. Current directory
3. Set path directory
Decision Making Statements
1. if statement
2. if ,else statement
3. if,else if,else if ,else construct
4. Switch case construct
if statement
if(condition)
statements ;
end
if else statement
if(condition)
statements ;
else
statements ;
end
if elseif elseif else construct
if(a>b)
statements ;
elseif(a<b)
statements ;
else
statements ;
end
Switch case construct
switch (choice)
case 1
statements;
case 2
statements;
case 3
statements;
case n
statements;
otherwise
statements;
end
Decision Making Statements
MATLAB Looping Statements
while loop
while n>0
statements;
statements;
statements;
end
 What is looping ??????
for loop
for f= 0.2 : 0.01 : 0.3
statements;
statements;
statements;
end
MATLAB Looping Statements
Excel data import in MATALAB
Plot diode characteristics by
importing excel data sheet with
current and voltage readings
Arrays and variables
Collections data values in the
form of matrix or vector
While giving name to an array
first 63 position are important
Array
1D 2D MD
Updating Array elements
a=[1,2;3,4;5,6];
a(5)
a(2,2)
a(3,1)
%%
b=[1 2 3;4 5 6;7 8 9];
b(1,2);
b(1:2,[1,3])=[11,12;13,14]
Row number
Column number
Plot function plots x,y data on linear axis
semilogx(x,y): function plots x data on
logarithmic axis and y data on linear axis
semilogy(x,y):function plots y data on
logarithmic axis and x data on linear axis
Loglog(x,y): function plots both x and y
data on logarithmic axis
Plots
  INTRODUCTION TO MATLAB   session with  notes
 2D plots
 bar(x,y) %bar plots
 stem(x,y) %stem plots
 stairs(x,y) %creates stair plots
 barh(x,y) %create horizontal bar plots
 pie(x) %create pie charts
 Polar(theta,r) %creates polar plots
 Mesh grid 3D plot %create 3D mesh plots
 Pole Zero Plot
Plots
Plot-1
Plot the function
y = x2 - 10x +15
For the value between 0 to 10
Plot-2
Next Session points to be covered
1. LDE solver
2. PDE solver
3. FFT Solver
4. Z-Transform Solver
5. L-Transform function
6. Curve Fitting problems
7. Introduction to optimization toolbox
8. Supervised neural training problem
9. Unsupervised neural training problem
10.Pattern recognition neural training
11.Frequency synthesis using MATLAB
12.Handling polynomial equations using MATLAB
13.Structure
14.Function handles
15.Class file access
16.FOL to CNF transformation
Next Session points to be covered
17.Resolution
18.Alpha Beta cut off
19.Predicated and propositional logic
20.Constraint satisfaction
21.Knowledge representation
22.Monotonic and Non monotonic reasoning
23.All search mechanism in details
 BFS
 DFS
 DLS
 Depth limited search
 Interactive Deeping Search
 Bi Directional search
 Best First search
 A*
 Greedy Search
THANK YOU
Image Source
searchenterpriseai.techtarget.com
wikipedia
Matlab Commands With
Example
%Matrix computations and operations
>> %creating vectors and matrices
>> %create a row vector, we can form a row vector.
>> a=[1 3 6 8];
>> a
a =
1 3 6 8
MATLAB Command With Syntax
>> %create a column vector,
>> b=[1;4;6;10];
>> b
b =
1
4
6
10
MATLAB Command With Syntax
>>Create the matrix x of 3 rows and 4 columns
x=[12 23 21 3; 2 34 5 7; 31 32 33 34];
>> x
x =
12 23 21 3
2 34 5 7
31 32 33 34
MATLAB Command With Syntax
%elements of a Matrix
>> z=x(2,3)
z = 5
>> x1=x(1,:)
x1 = 12 23 21 3
>> x2=x(:,2)
x2 =
23
34
32
>> s=size(x)
s = 3 4
MATLAB Command With Syntax
Remove the n th
X(n, : ) = [ ]
x(2, : ) = [ ]
Add a column of 4,s to the end of matrix.
x( ; , 4) = 4
MATLAB Command With Syntax
We can extend the colon notation to specify a
sequence
Create a vector v which starts at 1, with increment
of 2 and stops at 10:
v=1:2:10
v = 1 3 5 7 9
>> v=1:10
v = 1 2 3 4 5 6 7 8 9 10
MATLAB Command With Syntax
x=[11 12 13 14; 21 22 23 24;31 32 33 34];
>> x
x =
11 12 13 14
21 22 23 24
31 32 33 34
We can use this vector notation when
referring to sub matrix:
w=x(1:2:3, 2:4)
MATLAB Command With Syntax
w =
12 13 14
32 33 34
Rows :start at 1, increment by 2, stop at 3
Columns 2,3,4start at 2, stop at 4 default
increment of 1 is used
MATLAB Command With Syntax
x=[11 12 13 14;21 22 23 24 ;31 32 33 34 ]
x =
11 12 13 14
21 22 23 24
31 32 33 34
>> x4=x(1:2:3,2:4)
x4 =
12 13 14
32 33 34
MATLAB Command With Syntax
x4=x(1:2:2,2:4)
x4 =
12 13 14
>> x4=x(1:1:3,2:4)
x4 =
12 13 14
22 23 24
32 33 34
MATLAB Command With Syntax
x4=x(1:1:2,2:4)
x4 =
12 13 14
22 23 24
x4=[x;41 42 43 44]
x4 =
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
x= [41 42 43 44;x] ?
MATLAB Command With Syntax
x4 = x(2:1:3,2:4)
x4 =
22 23 24
32 33 34
x(4 , : ) = [41 42 43 44]
x =
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
MATLAB Command With Syntax
x4=x(1:1:2,1:4)
x4 =
11 12 13 14
21 22 23 24
>> x4=x(1:1:2,2:4)
x4 =
12 13 14
22 23 24
>> x4=x(1:1:2,3:4)
x4 =
13 14
23 24
MATLAB Command With Syntax
Strings
String handling
Syntax
S = 'Any Characters'
S = [S1 S2 ...]
S = strcat(S1, S2, ...)
MATLAB Command With Syntax
Examples
Create a simple string that includes a single quote.
msg = 'You''re right!'
msg =
You're right!
Create the string name using two methods of
concatenation.
name = ['Thomas' ' R. ' 'Lee']
name = strcat('Thomas',' R.',' Lee')
MATLAB Command With Syntax
Create a vertical array of strings.
C = strvcat('Hello','Yes','No','Goodbye‘)
C =
Hello
Yes
No
Goodbye
MATLAB Command With Syntax
S = {'Hello' 'Yes' 'No' 'Goodbye'}
S =
'Hello' 'Yes' 'No' 'Goodbye'
Create a cell array of strings.
S = {'Hello' 'Yes' 'No' 'Goodbye}
MATLAB Command With Syntax
1. Commands for Managing a Session
2. MATLAB provides various commands for managing a session.
3. The following table provides all such commands −
4. I have forgotten the Variables!
5. The who command displays all the variable names you have
used.
6. who
7. MATLAB will execute the above statement and return the
following result
MATLAB Command With Syntax
>> who
Your variables are:
a b x
>> whos
Name Size Bytes Class Attributes
a 1x4 32 double
b 4x1 32 double
x 3x4 96 double
MATLAB Command With Syntax
whos
Name Size Bytes Class Attributes
a 1x4 32 double
b 4x1 32 double
x 3x4 96 double
MATLAB Command With Syntax
Basic Task: Plot the function sin(x) between 0≤x≤4π
 Create an x-array of 100 samples between 0 and 4π.
 Calculate sin(.) of the x-array
 Plot the y-array
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>plot(y)
0 10 20 30 40 50 60 70 80 90 100
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
MATLAB Command With Syntax
Plot the function e-x/3sin(x) between 0≤x≤4π
 Create an x-array of 100 samples between 0 and 4π.
 Calculate sin(.) of the x-array
 Calculate e-x/3 of the x-array
 Multiply the arrays y and y1
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>y1=exp(-x/3);
>>y2=y.*y1;
MATLAB Command With Syntax
Plot the function e-x/3sin(x) between 0≤x≤4π
 Multiply the arrays y and y1 correctly
 Plot the y2-array
>>y2=y.*y1;
>>plot(y2)
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
MATLAB Command With Syntax
Display Facilities
 plot(.)
 stem(.)
Example:
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>plot(y)
>>plot(x,y)
Example:
>>stem(y)
>>stem(x,y)
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
MATLAB Command With Syntax
Display Facilities
 title(.)
 xlabel(.)
 ylabel(.)
>>title(‘This is the sinus function’)
>>xlabel(‘x (secs)’)
>>ylabel(‘sin(x)’)
0 10 20 30 40 50 60 70 80 90 100
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
This is the sinus function
x (secs)
sin(x)
MATLAB Command With Syntax
Operators (relational, logical)
 == Equal to
 ~= Not equal to
 < Strictly smaller
 > Strictly greater
 <= Smaller than or equal to
 >= Greater than equal to
 & And operator
 | Or operator
 ~ NOT
MATLAB Command With Syntax
Name Meaning
ans Most recent answer.
eps Accuracy of floating-point precision.
i,j The imaginary unit √-1.
Inf Infinity.
NaN Undefined numerical result (not a
number).
pi The number π
Special Variables and Constants
MATLAB supports the following special variables and constants:
MATLAB Command With Syntax
Multiple Assignments
You can have multiple assignments on the same
line.
For example,
a = 2; b = 7; c = a * b
MATLAB will execute the above statement and
return the following result −
c = 14
MATLAB Command With Syntax
The clear command deletes all (or the specified)
variable(s) from the memory.
clear x % it will delete x, won't display anything
clear % it will delete all variables in the
% workspace
% peacefully and unobtrusively
MATLAB Command With Syntax
Command Purpose
clc Clears command window.
clear Removes variables from memory.
exist Checks for existence of file or variable.
global Declares variables to be global.
help Searches for a help topic.
lookfor Searches help entries for a keyword.
quit Stops MATLAB.
who Lists current variables.
whos Lists current variables (long display).
Commands for Managing a Session
MATLAB provides various commands for managing a session.
The following table provides all such commands −
MATLAB Command With Syntax
MATLAB provides various useful commands for
working with the system, like saving the current work
in the workspace as a file and loading the file later.
It also provides various commands for other system-
related activities like, displaying date, listing files in
the directory, displaying current directory, etc.
MATLAB Command With Syntax
Command Purpose
cd Changes current directory.
date Displays current date.
delete Deletes a file.
diary Switches on/off diary file recording
Commands for Working with the System
The following table displays some commonly used system-related commands −
MATLAB Command With Syntax
Command Purpose
disp Displays contents of an array or string.
fscanf Read formatted data from a file.
format Controls screen-display format.
fprintf Performs formatted writes to screen or file.
input Displays prompts and waits for input.
; Suppresses screen printing.
Input and Output Commands
MATLAB provides the following
Input and output related commands −
MATLAB Command With Syntax
Assignments
1. Create a matrix A of zeros [2x4], and B of ones[2x3].
i. Add A by 2 to create matrix of twos.
ii. Can we add A+B? and A-B? justify your Answer.
2. Create matrix of 4 rows and 3 columns.
i. Add X by 4 to create new matrix called Y.
ii. Form C= X+Y
iii. Form D= X-Y
iv. Remove second row.
v. Add a column of 4’s to the end of matrix.
3. Using matrix operations to solve the following system of linear equations.
4x - 2y + 6z = 8
2x + 8y + 2z = 4
6x +10y +3z = 0.
MATLAB Command With Syntax
THANK YOU
Image Source
searchenterpriseai.techtarget.com
wikipedia

More Related Content

PDF
Programming with matlab session 6
PDF
Programming with matlab session 1
PPTX
Introduction to matlab lecture 3 of 4
PPTX
Introduction to matlab lecture 2 of 4
PPT
Introduction to MATLAB
PPTX
Intro to Matlab programming
PDF
Network Security CS3-4
PDF
Matlab solved problems
Programming with matlab session 6
Programming with matlab session 1
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 2 of 4
Introduction to MATLAB
Intro to Matlab programming
Network Security CS3-4
Matlab solved problems

What's hot (20)

PPTX
matlab
PPTX
Matlab Tutorial
PPT
Matlab introduction
PDF
Basics of MATLAB programming
PPTX
PPT
Matlab1
DOCX
B61301007 matlab documentation
PPTX
2D Plot Matlab
PPTX
Introduction to matlab
PDF
A complete introduction on matlab and matlab's projects
PDF
Matlab-free course by Mohd Esa
PDF
MATLAB for Technical Computing
PPT
Matlab intro
PPT
Matlab anilkumar
PDF
Matlab practice
PPT
Learn Matlab
PPTX
Intro to matlab
PDF
Matlab Graphics Tutorial
PDF
Lec 8 03_sept [compatibility mode]
PPTX
Lectue five
matlab
Matlab Tutorial
Matlab introduction
Basics of MATLAB programming
Matlab1
B61301007 matlab documentation
2D Plot Matlab
Introduction to matlab
A complete introduction on matlab and matlab's projects
Matlab-free course by Mohd Esa
MATLAB for Technical Computing
Matlab intro
Matlab anilkumar
Matlab practice
Learn Matlab
Intro to matlab
Matlab Graphics Tutorial
Lec 8 03_sept [compatibility mode]
Lectue five
Ad

Similar to INTRODUCTION TO MATLAB session with notes (20)

PPTX
1. Introduction.pptx
PDF
Introduction to matlab
PDF
Introduction to matlab
PPTX
Introduction to matlab
PPTX
An Introduction to MATLAB for beginners
PDF
Introduction to Matlab.pdf
PPTX
Introduction to Matlab and application.pptx
PPT
Introduction to Matlab - Basic Functions
DOCX
Introduction to matlab
PPTX
1. Ch_1 SL_1_Intro to Matlab.pptx
PDF
Matlab booklet
PPTX
From zero to MATLAB hero: Mastering the basics and beyond
PDF
Matlab for beginners, Introduction, signal processing
PPTX
intro2matlab-basic knowledge about Matlab.pptx
PPTX
Raushan's MATLB PPT..pptx
PPTX
Introduction to MATLAB Programming for Engineers
PPT
MATLAB-Introd.ppt
PPT
matlab tutorial with separate function description and handson learning
DOCX
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
PPT
MatlabIntro1234.ppt.....................
1. Introduction.pptx
Introduction to matlab
Introduction to matlab
Introduction to matlab
An Introduction to MATLAB for beginners
Introduction to Matlab.pdf
Introduction to Matlab and application.pptx
Introduction to Matlab - Basic Functions
Introduction to matlab
1. Ch_1 SL_1_Intro to Matlab.pptx
Matlab booklet
From zero to MATLAB hero: Mastering the basics and beyond
Matlab for beginners, Introduction, signal processing
intro2matlab-basic knowledge about Matlab.pptx
Raushan's MATLB PPT..pptx
Introduction to MATLAB Programming for Engineers
MATLAB-Introd.ppt
matlab tutorial with separate function description and handson learning
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
MatlabIntro1234.ppt.....................
Ad

More from Infinity Tech Solutions (20)

PDF
Database management system session 6
PDF
Database management system session 5
PDF
Database Management System-session 3-4-5
PDF
Database Management System-session1-2
PDF
Main topic 3 problem solving and office automation
PDF
Introduction to c programming
PDF
PDF
Bds session 13 14
PDF
Computer memory, Types of programming languages
PDF
Basic hardware familiarization
PDF
User defined functions in matlab
PDF
Programming with matlab session 3 notes
PPTX
AI/ML/DL/BCT A Revolution in Maritime Sector
PDF
Programming with matlab session 5 looping
PDF
BIG DATA Session 7 8
PDF
BIG DATA Session 6
PDF
Database management system session 6
Database management system session 5
Database Management System-session 3-4-5
Database Management System-session1-2
Main topic 3 problem solving and office automation
Introduction to c programming
Bds session 13 14
Computer memory, Types of programming languages
Basic hardware familiarization
User defined functions in matlab
Programming with matlab session 3 notes
AI/ML/DL/BCT A Revolution in Maritime Sector
Programming with matlab session 5 looping
BIG DATA Session 7 8
BIG DATA Session 6

Recently uploaded (20)

PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Geodesy 1.pptx...............................................
PDF
Well-logging-methods_new................
PPTX
Welding lecture in detail for understanding
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Construction Project Organization Group 2.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
DOCX
573137875-Attendance-Management-System-original
PDF
composite construction of structures.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Mechanical Engineering MATERIALS Selection
Geodesy 1.pptx...............................................
Well-logging-methods_new................
Welding lecture in detail for understanding
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
OOP with Java - Java Introduction (Basics)
R24 SURVEYING LAB MANUAL for civil enggi
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
additive manufacturing of ss316l using mig welding
Internet of Things (IOT) - A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Construction Project Organization Group 2.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
573137875-Attendance-Management-System-original
composite construction of structures.pdf
Digital Logic Computer Design lecture notes
Automation-in-Manufacturing-Chapter-Introduction.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...

INTRODUCTION TO MATLAB session with notes

  • 2. Session Objective MATLAB INTRODUCTION IDE ,COMMANDS ,RESULTS ,M FILE CONDITIONAL STATEMENTS (if,switch) LOOPING STATEMENTS, ARRAYS ,FILE HANDLING SUMMARY
  • 3. MATLAB Applications 1. Communication engineering 2. AI,ML,DL 3. Image processing 4. Optimization 5. Data access ,analysis and visualization 6. Programming and algorithm designing 7. Performance analysis of algorithms 8. Simulink
  • 4. MATLAB Commands 1. date 2. clock 3. ver 4. whos 5. what(files in current dir) 6. clc 7. clear 8. diary filename 9. diary off 10. diary on 11. path 12. editpath GUI ,home,set path 13.! DOS command 14. exit
  • 5. MATLAB Operators/Symbols/Functions 1. + 2. - 3. * 4. / 5. ^ 6. = 7. == 8. pi 9. vpa (digit precision) 10. % 11. ; 12. : range 13.randn() %10, 1:1:10; 14. Ctrl+c 15. ceil 16. floor 17. sqrt 18. Matrix (+,-,*) 19. ‘.’ operator 20. eye 21. zeros(5) 22. ` transpose 23. ones(6)
  • 6. MATLAB Operators/Symbols/Functions 24. imread() 25. imshow 26. disp() 27. input() 28. factorial() 29. length(a) 30. size(a) 31. fprintf()-only o/p 32. sprintf()-o/p with save in workspace 33. format rat/ long /hex /shortEng/logEng 34. de2bi, d=(1:10)’; b=de2bi(d); [d,b] 35. decimalToBinaryVector(x);MSB,LSB
  • 7. MATLAB Operators/Symbols/Functions 36. All trigonometric values and error o/p 37. cosd(),sind() 38. All hyperbolic trigonometric values 39. mod(x,y) 40. log(x) %natural log 41. log10(x)
  • 8. MATLAB Variables and Data types Data types Logical Char Numeric Int 8 unint 8 Int 16 unint 16 Int 32 unint 32 Int 64 unint 64 Single Double Structure Function Handle
  • 9. Typing Mathematical Expression 1) R1= −𝑏+ 𝑏2−4𝑎𝑐 2𝑎 R2= −𝑏± 𝑏 2 −4𝑎𝑐 2𝑎 2) R1= 𝑎2 + 𝑏2 e-0.2t cos 2t 3) E=mc2 Y=1 + 𝑛𝑥 1! + 𝑛 𝑛−1 𝑥2 2!
  • 10. MATLAB Code File 1. File name should not start with number 2. No Space in the file name 3. No library function name 4. No use of keywords reserved by MATALAB MATLAB Searching Mechanism 1. Workspace 2. Current directory 3. Set path directory
  • 11. Decision Making Statements 1. if statement 2. if ,else statement 3. if,else if,else if ,else construct 4. Switch case construct if statement if(condition) statements ; end if else statement if(condition) statements ; else statements ; end if elseif elseif else construct if(a>b) statements ; elseif(a<b) statements ; else statements ; end
  • 12. Switch case construct switch (choice) case 1 statements; case 2 statements; case 3 statements; case n statements; otherwise statements; end Decision Making Statements
  • 13. MATLAB Looping Statements while loop while n>0 statements; statements; statements; end  What is looping ??????
  • 14. for loop for f= 0.2 : 0.01 : 0.3 statements; statements; statements; end MATLAB Looping Statements
  • 15. Excel data import in MATALAB Plot diode characteristics by importing excel data sheet with current and voltage readings
  • 16. Arrays and variables Collections data values in the form of matrix or vector While giving name to an array first 63 position are important Array 1D 2D MD
  • 17. Updating Array elements a=[1,2;3,4;5,6]; a(5) a(2,2) a(3,1) %% b=[1 2 3;4 5 6;7 8 9]; b(1,2); b(1:2,[1,3])=[11,12;13,14] Row number Column number
  • 18. Plot function plots x,y data on linear axis semilogx(x,y): function plots x data on logarithmic axis and y data on linear axis semilogy(x,y):function plots y data on logarithmic axis and x data on linear axis Loglog(x,y): function plots both x and y data on logarithmic axis Plots
  • 20.  2D plots  bar(x,y) %bar plots  stem(x,y) %stem plots  stairs(x,y) %creates stair plots  barh(x,y) %create horizontal bar plots  pie(x) %create pie charts  Polar(theta,r) %creates polar plots  Mesh grid 3D plot %create 3D mesh plots  Pole Zero Plot Plots
  • 21. Plot-1 Plot the function y = x2 - 10x +15 For the value between 0 to 10 Plot-2
  • 22. Next Session points to be covered 1. LDE solver 2. PDE solver 3. FFT Solver 4. Z-Transform Solver 5. L-Transform function 6. Curve Fitting problems 7. Introduction to optimization toolbox 8. Supervised neural training problem 9. Unsupervised neural training problem 10.Pattern recognition neural training 11.Frequency synthesis using MATLAB 12.Handling polynomial equations using MATLAB 13.Structure 14.Function handles 15.Class file access 16.FOL to CNF transformation
  • 23. Next Session points to be covered 17.Resolution 18.Alpha Beta cut off 19.Predicated and propositional logic 20.Constraint satisfaction 21.Knowledge representation 22.Monotonic and Non monotonic reasoning 23.All search mechanism in details  BFS  DFS  DLS  Depth limited search  Interactive Deeping Search  Bi Directional search  Best First search  A*  Greedy Search
  • 26. %Matrix computations and operations >> %creating vectors and matrices >> %create a row vector, we can form a row vector. >> a=[1 3 6 8]; >> a a = 1 3 6 8 MATLAB Command With Syntax
  • 27. >> %create a column vector, >> b=[1;4;6;10]; >> b b = 1 4 6 10 MATLAB Command With Syntax
  • 28. >>Create the matrix x of 3 rows and 4 columns x=[12 23 21 3; 2 34 5 7; 31 32 33 34]; >> x x = 12 23 21 3 2 34 5 7 31 32 33 34 MATLAB Command With Syntax
  • 29. %elements of a Matrix >> z=x(2,3) z = 5 >> x1=x(1,:) x1 = 12 23 21 3 >> x2=x(:,2) x2 = 23 34 32 >> s=size(x) s = 3 4 MATLAB Command With Syntax
  • 30. Remove the n th X(n, : ) = [ ] x(2, : ) = [ ] Add a column of 4,s to the end of matrix. x( ; , 4) = 4 MATLAB Command With Syntax
  • 31. We can extend the colon notation to specify a sequence Create a vector v which starts at 1, with increment of 2 and stops at 10: v=1:2:10 v = 1 3 5 7 9 >> v=1:10 v = 1 2 3 4 5 6 7 8 9 10 MATLAB Command With Syntax
  • 32. x=[11 12 13 14; 21 22 23 24;31 32 33 34]; >> x x = 11 12 13 14 21 22 23 24 31 32 33 34 We can use this vector notation when referring to sub matrix: w=x(1:2:3, 2:4) MATLAB Command With Syntax
  • 33. w = 12 13 14 32 33 34 Rows :start at 1, increment by 2, stop at 3 Columns 2,3,4start at 2, stop at 4 default increment of 1 is used MATLAB Command With Syntax
  • 34. x=[11 12 13 14;21 22 23 24 ;31 32 33 34 ] x = 11 12 13 14 21 22 23 24 31 32 33 34 >> x4=x(1:2:3,2:4) x4 = 12 13 14 32 33 34 MATLAB Command With Syntax
  • 35. x4=x(1:2:2,2:4) x4 = 12 13 14 >> x4=x(1:1:3,2:4) x4 = 12 13 14 22 23 24 32 33 34 MATLAB Command With Syntax
  • 36. x4=x(1:1:2,2:4) x4 = 12 13 14 22 23 24 x4=[x;41 42 43 44] x4 = 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44 x= [41 42 43 44;x] ? MATLAB Command With Syntax
  • 37. x4 = x(2:1:3,2:4) x4 = 22 23 24 32 33 34 x(4 , : ) = [41 42 43 44] x = 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44 MATLAB Command With Syntax
  • 38. x4=x(1:1:2,1:4) x4 = 11 12 13 14 21 22 23 24 >> x4=x(1:1:2,2:4) x4 = 12 13 14 22 23 24 >> x4=x(1:1:2,3:4) x4 = 13 14 23 24 MATLAB Command With Syntax
  • 39. Strings String handling Syntax S = 'Any Characters' S = [S1 S2 ...] S = strcat(S1, S2, ...) MATLAB Command With Syntax
  • 40. Examples Create a simple string that includes a single quote. msg = 'You''re right!' msg = You're right! Create the string name using two methods of concatenation. name = ['Thomas' ' R. ' 'Lee'] name = strcat('Thomas',' R.',' Lee') MATLAB Command With Syntax
  • 41. Create a vertical array of strings. C = strvcat('Hello','Yes','No','Goodbye‘) C = Hello Yes No Goodbye MATLAB Command With Syntax
  • 42. S = {'Hello' 'Yes' 'No' 'Goodbye'} S = 'Hello' 'Yes' 'No' 'Goodbye' Create a cell array of strings. S = {'Hello' 'Yes' 'No' 'Goodbye} MATLAB Command With Syntax
  • 43. 1. Commands for Managing a Session 2. MATLAB provides various commands for managing a session. 3. The following table provides all such commands − 4. I have forgotten the Variables! 5. The who command displays all the variable names you have used. 6. who 7. MATLAB will execute the above statement and return the following result MATLAB Command With Syntax
  • 44. >> who Your variables are: a b x >> whos Name Size Bytes Class Attributes a 1x4 32 double b 4x1 32 double x 3x4 96 double MATLAB Command With Syntax
  • 45. whos Name Size Bytes Class Attributes a 1x4 32 double b 4x1 32 double x 3x4 96 double MATLAB Command With Syntax
  • 46. Basic Task: Plot the function sin(x) between 0≤x≤4π  Create an x-array of 100 samples between 0 and 4π.  Calculate sin(.) of the x-array  Plot the y-array >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) 0 10 20 30 40 50 60 70 80 90 100 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 MATLAB Command With Syntax
  • 47. Plot the function e-x/3sin(x) between 0≤x≤4π  Create an x-array of 100 samples between 0 and 4π.  Calculate sin(.) of the x-array  Calculate e-x/3 of the x-array  Multiply the arrays y and y1 >>x=linspace(0,4*pi,100); >>y=sin(x); >>y1=exp(-x/3); >>y2=y.*y1; MATLAB Command With Syntax
  • 48. Plot the function e-x/3sin(x) between 0≤x≤4π  Multiply the arrays y and y1 correctly  Plot the y2-array >>y2=y.*y1; >>plot(y2) 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 MATLAB Command With Syntax
  • 49. Display Facilities  plot(.)  stem(.) Example: >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) >>plot(x,y) Example: >>stem(y) >>stem(x,y) 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 MATLAB Command With Syntax
  • 50. Display Facilities  title(.)  xlabel(.)  ylabel(.) >>title(‘This is the sinus function’) >>xlabel(‘x (secs)’) >>ylabel(‘sin(x)’) 0 10 20 30 40 50 60 70 80 90 100 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 This is the sinus function x (secs) sin(x) MATLAB Command With Syntax
  • 51. Operators (relational, logical)  == Equal to  ~= Not equal to  < Strictly smaller  > Strictly greater  <= Smaller than or equal to  >= Greater than equal to  & And operator  | Or operator  ~ NOT MATLAB Command With Syntax
  • 52. Name Meaning ans Most recent answer. eps Accuracy of floating-point precision. i,j The imaginary unit √-1. Inf Infinity. NaN Undefined numerical result (not a number). pi The number π Special Variables and Constants MATLAB supports the following special variables and constants: MATLAB Command With Syntax
  • 53. Multiple Assignments You can have multiple assignments on the same line. For example, a = 2; b = 7; c = a * b MATLAB will execute the above statement and return the following result − c = 14 MATLAB Command With Syntax
  • 54. The clear command deletes all (or the specified) variable(s) from the memory. clear x % it will delete x, won't display anything clear % it will delete all variables in the % workspace % peacefully and unobtrusively MATLAB Command With Syntax
  • 55. Command Purpose clc Clears command window. clear Removes variables from memory. exist Checks for existence of file or variable. global Declares variables to be global. help Searches for a help topic. lookfor Searches help entries for a keyword. quit Stops MATLAB. who Lists current variables. whos Lists current variables (long display). Commands for Managing a Session MATLAB provides various commands for managing a session. The following table provides all such commands − MATLAB Command With Syntax
  • 56. MATLAB provides various useful commands for working with the system, like saving the current work in the workspace as a file and loading the file later. It also provides various commands for other system- related activities like, displaying date, listing files in the directory, displaying current directory, etc. MATLAB Command With Syntax
  • 57. Command Purpose cd Changes current directory. date Displays current date. delete Deletes a file. diary Switches on/off diary file recording Commands for Working with the System The following table displays some commonly used system-related commands − MATLAB Command With Syntax
  • 58. Command Purpose disp Displays contents of an array or string. fscanf Read formatted data from a file. format Controls screen-display format. fprintf Performs formatted writes to screen or file. input Displays prompts and waits for input. ; Suppresses screen printing. Input and Output Commands MATLAB provides the following Input and output related commands − MATLAB Command With Syntax
  • 59. Assignments 1. Create a matrix A of zeros [2x4], and B of ones[2x3]. i. Add A by 2 to create matrix of twos. ii. Can we add A+B? and A-B? justify your Answer. 2. Create matrix of 4 rows and 3 columns. i. Add X by 4 to create new matrix called Y. ii. Form C= X+Y iii. Form D= X-Y iv. Remove second row. v. Add a column of 4’s to the end of matrix. 3. Using matrix operations to solve the following system of linear equations. 4x - 2y + 6z = 8 2x + 8y + 2z = 4 6x +10y +3z = 0. MATLAB Command With Syntax