Lab No.3
Lab No.3
Lab No.3
Lab No.3
Submitted By:
Muhammad Hassan (2020-MC-274)
Submitted to:
Dr. Arshi Khalid
--------------------------------------------------------------------------------------------------------
-
Date: 06-10-2022
Flow Control:-
Computer programming languages offer features that allow you to control the flow of
command execution based on decision making structures. MATLAB has several flow control constructions:
o If-Else statement.
o Switch and case statement.
o For Loop.
Matlab Commands:
To make pie chart:
pie (name_of_array)
For example, if v is an array having elements [1,2,3;4,5,6;7,8,9] then pie(v) will give us a pie chart of v.
bar (name_of_array)
For example, if v is an array having elements [1,2,3;4,5,6;7,8,9] then bar(v) will give us a bar chart of v.
2
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid
Pie3(name_of_array)
For example, if v is an array having elements [1,2,3;4,5,6;7,8,9] then pie3(v) will give us a 3d pie chart
of v.
Matlab Code:
1. method = 'Bilinear';
2. switch lower(method)
3. case 'bilinear'
a. disp('Method is Bilinear')
4. case 'cubic'
a. disp('Method is cubic')
5. case 'nearest'
a. disp('Method is nearest')
6. otherwise
a. disp('Unknown method.')
7. end
It gives the answer “Method is Bilinear”.
1. x = [1,23,45];
2. method = 'bar';
3. switch (method)
4. case 'pie'
a. disp(pie(x))
5. case 'bar'
a. disp(bar(x))
6. end
3
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid
4
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid
Result:
Use of If-Else:
if condition 1
Statement 1
elseif condition 2
Statement 2
else condition 3
Statement 3
end
For example, if we have Z = 3*x^2 + 2*x – 1 and we have to find it’s discriminant for real or
complex values then.
1. syms x;
2. Z = 3*x^2 + 2*x - 1
3. a = 3;
4. b= 2;
5. c = -1;
6. disc = b^2 - 4*a*c
7. if disc == 0
8. disp('Discrminent is real and equal')
9. elseif disc>0
10. disp('Discriminant is real')
11. else disc<0
12. disp('Discriminat is iamginary')
13. end
disc = 16
Discriminant is real
5
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid
Matlab Code:
1. for a=1:5
2. for b=1:5
a. c(a,b)=a*b;
3. end
4. end
5. c