Signals and Systems
(BE03000171)
[Link] 3rd Semester
Department of Electronics & Communication
Engineering
L.D. College of Engineering, Ahmedabad
NAME : RIDDHI PATEL
ENROLLMENT NO. : 240280111128
DIVISION : B
LAB WORK – 1
1. Creating vectors
(a) Generate the following vectors:
A = [1 0 4 5 3 9 0 2]
a = [4 5 0 2 0 0 7 1]
Be aware that Matlab are case sensitive. Vector A and a have different values.
Ans
My Code :
The output at the command window :
(b) Generate the following vectors:
B = [A a]
C = [a,A]
Concatenation is the process of joining small matrices to make bigger ones. In fact, you
made your first matrix by concatenating its individual elements. The pair of square
brackets, [ ], is the concatenation operator.
Ans
My Code :
The output at the command window :
(c) Generate the following vectors using function zeros and ones:
D = [0 0 0 ... 0] with fifty 0’s.
E = [1 1 1 ... 1] with a hundred 1’s.
Ans
My Code :
The output at the command window :
(d) Generate the following vectors using the colon operator
F = [1 2 3 4 …... 30]
G = [25 22 19 16 13 10 7 4 1]
H = [0 0.2 0.4 0.6 ... …..2.0]
The colon, :, is one of Matlab’s most important operators.
Ans
My Code :
The output at the command window :
2. Operate with the vectors
V1 = [1 2 3 4 5 6 7 8 9 0]
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9]
V3 = [4 4 4 4 3 3 2 2 2 1]
(a) Calculate, respectively, the sum of all the elements in vectors V1, V2, and V3.
Ans
My Code :
The output at the command window :
(b) How to get the value of the fifth element of each vector?
What happens if we execute the command V1(0) and V1(11)?
Remember if a vector has N elements, their subscripts are from 1 to N.
Ans
My Code :
The output at the command window :
(c) Generate a new vector V4 from V2, which is composed of the first five elements of V2.
Generate a new vector V5 from V2, which is composed of the last five elements of V2.
Ans
My Code :
The output at the command window :
(d) Derive a new vector V6 from V2, with its 6th element omitted.
Derive a new vector V7 from V2, with its 7th element changed to 1.4.
Derive a new vector V8 from V2, whose elements are the 1st, 3rd, 5th, 7th, and 9th
elements of V2
Ans
My Code :
The output at the command window :
(E) What are the results of
9-V1
V1*5
V1+V2
V1-V3
V1.*V2
V1*V2
V1.^2
V1.^V3
V1^V3
V1 == V3
V1>6
V1>V3
V3-(V1>2)
(V1>2) & (V<6) (V1>2) | (V1<6)
any(V1)
all(V1)
Ans
My Code :
The output at the command window :
3. Using Matlab help system, click on
Help -> MATLAB help or type helpdesk to can open the help files. For description of a single
function or command, type help command_name on the command line, or use ’search’ in
the help window. For example, type help plot or help all or help any on the command line.
Ans
The Result :
4. Flow control What are the results of these sets of commands?
Think them over and run them with Matlab to see if you are
right.
(a) A = zeros(1,5);
for n = 1:4
for m = 1:3
A = A + n*m;
end
end
A
Ans
My Code :
The output at the command window :
(b) B = [1 2 3 0]; %%%B=[1 1 1 1]; B=[0 0 0 0]
if (all(B))
B = B + 1;
elseif (any(B))
B = B + 2;
else
B = B + 3;
end
B
Ans
My Code :
The output at the command window :