AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
EXPERIMENT NO 1
Lab Title: INTRODUCTION TO MATLAB
Student Name: Yehia Maged Reg. No: 222692
Objective: To gain hands-on familiarity with the MATLAB software and understand the basic
Matrix operations,
LAB ASSESSMENT:
Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules
Total Marks: Obtained Marks:
LAB REPORT ASSESSMENT:
Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)
Data presentation
Experimental results
Conclusion
Total Marks: Obtained Marks:
Date: Signature:
•
2|Page
3|Page
4|Page
5|Page
6|Page
7|Page
8|Page
9|Page
10 | P a g e
if expression
statements
else
statements
end
11 | P a g e
12 | P a g e
π
π
13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
r = randi([-10,10],1,1)
Code:
clc
r=randi([-10,10],1,1)
a=input('enter a number= ');
if r==a
disp('Congratulations')
else
disp('Better luck next time')
end
18 | P a g e
≠
Main Code:
clc
A = input('enter a matrix= ');
m = matrixsymm(A);
Function Code using if-else:
function m = matrixsymm(A)
if A==A'
disp('The Entered Matrix is symmetric')
m=1;
else
disp('The Entered Matrix is not symmetric')
m=0;
end
Main Code:
clc
A = input('enter a matrix= ');
m = matrixsymm(A);
Function Code using For loop:
function m = matrixsymm(A)
[m, n] = size(A);
isSymmetric = 1;
for i = 1:m
for j = 1:n
if A(i, j) ~= A(j, i)
isSymmetric = 0;
break;
end
end
if ~isSymmetric
break;
end
end
19 | P a g e
if isSymmetric
disp('The Entered Matrix is symmetric');
m = 1;
else
disp('The Entered Matrix is not symmetric');
m = 0;
end
end
Main Code:
clc
A = input('enter a matrix= ');
m = matrixsymm(A);
Function Code using while loop:
i = 1;
while i <= 1
if A == A'
disp('The Entered Matrix is symmetric');
m = 1;
else
disp('The Entered Matrix is not symmetric');
m = 0;
end
i = i + 1;
end
end
20 | P a g e
Code:
clc
n=-2:10;
x=[0 2 5 6 5 2 6 5 2 0 0 0 0];
stem(n,x,"filled",'k',"LineWidth",3)
title('DT signal')
xlabel('n')
ylabel('x[n]')
axis([-3 11 0 7])
21 | P a g e
𝑁
𝑦 = ∑ 𝑛2
𝑛=1
Code(x=1000):
clc
x=1000;
y=0;
N=0;
while(x-y>0.1)
y=y+N.^2;
N=N+1;
end
N
Code(x=100):
clc
x=100;
y=0;
N=0;
while(x-y>0.1)
y=y+N.^2;
N=N+1;
end
N
22 | P a g e
5. Desing Bulgaria flag on MATLAB.
Code:
clc
figure
one=[0 0 200 50];
two=[0 50 200 50];
three=[0 100 200 50];
rectangle('Position',one,'facecolor','r')
rectangle('Position',two,'facecolor','g')
rectangle('Position',three,'facecolor','w')
23 | P a g e
Conclusion:
In this lab, we have successfully gained hands-on experience with MATLAB, exploring its essential
features, including matrix operations, conditional statements, and graphical representations. We
implemented various tasks to check matrix symmetry using if-else, For loop, and while loop,
generate random numbers, visualize discrete signals using the stem function, and MATLAB’s
graphical functions. This experiment provided valuable hands-on experience with MATLAB
programming, reinforcing key concepts in numerical computing and data visualization.
24 | P a g e