Professional Documents
Culture Documents
(FALL-2020)
Submitted By:
Submitted To:
SIR USMAN
(Lecturer)
Objectives/lab goals:
Learning basics commands such as:
disp
table
zeros
ones
Logical operators
Conditions (do while, while loop)
Non-conditional (For loops)
Nested for loop
1. disp command
MATLAB program outputs can be made more informative by using the disp function. The purpose
of this function is to display text or variable values on screen.
Anything can be printed using disp command in matlab.
To display lines inverted commas are use and if to call a variable just write its name without commas
inside the parentheses.
1) Initialize a variable and extract its value from user using input function.
2) Ask the user to enter “your marks”.
3) Use if condition that if the given marks is greater than 80, the disp command will executes and
will print “good”.
4) And if the case is wrong, means the entered marks are less than the 80, disp will print “fail”.
5) And this condition will be terminated by end keyword.
3. zeros
A matrix containing all elements zeros is generated here.
4. ones
A matrix containing all elements equal to one.
Figure 6: usage of logical operators Figure 7: the ‘1’ shows that these two conditions are
true.
6. non-conditional(for loop)
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to
execute a specific number of times.
Syntax
The syntax of a for loop in MATLAB is −
for index = values
code for looping
end
1) Variable named a is use for taking input from user.
2) Than for loop is initialized for a number of times what a will be entered.
3) Code is written inside the For loop and end keyword is written to terminate loop.
Figure 8: a for loop is used and its syntax is shown Figure 9: the end result of for loop is shown here
Lab-02 biomedical imaging
Sumbal Zahra Ameen
2017-BET-BMED-27
7. nested for loop
1. A for loop is initialized inside another for loop.
2. First the outer loop will run then the inside loop will run for the number of times the y is true.
3. Then the inside loop will terminate and the outer loop will run for next iteration.
4. Thus outer and inner loops will work.
8. If else
Syntax
If expression
statements
elseif expression
statements
else
statements
end
Description:
1) if expression, statements, end evaluates an expression, and executes a group of statements when
the expression is true. An expression is true when its result is nonempty and contains only
nonzero elements (logical or real numeric). Otherwise, the expression is false.
2) The elseif and else blocks are optional. The statements execute only if previous expressions in
the if...end block are false. An if block can include multiple elseif blocks.
Input the temperature from the user in centigrade and convert it into feranhight.
Temperature changing
1) Input command is use to take input temperature which is in centigrade is assigned to the tempc
variable.
2) The formula to change centigrade into Fahrenheit is assigned to another variable named as
tempf.