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
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
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
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
19.
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
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
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
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