Lab Report 2
Lab Report 2
For
B.E. Computer Engineering
Objective:
The objective of this lab is to create an understanding of using loops and conditional
statements in MATLAB. It also introduces the basics of plotting signals.
Tasks:
Task 1:
Write a MATLAB code to display the following using for loop, while loop and if
statements separately:
For Loop:
First 30 numbers
Even numbers
Odd numbers
While Loop:
First 30 numbers
Even numbers
Odd numbers
If else:
Task 2:
(a) Check whether the following set of commands :
for i = 1:20
H(i) = i * 5
End
have the same result as:
H = 1:20;
H = H*5
These two sets of commands have the same result as first command generates a vector and
fills it using for loop from 1 to 20 while the second command generates a vector using colon
operator from 1 to 20. Both vectors have 1 row and 20 columns and contain the same values.
Task 4:
For the following, use the signal described as:
t=0:0.2:2*pi
Put two plots on the same axis, i.e. sin(t) and sin(2t)
Produce a plot without connecting the points