You are on page 1of 6

Lab-02 biomedical imaging

Sumbal Zahra Ameen


2017-BET-BMED-27

BIOMEDICAL IMAGING (BMT-411L)


Lab02 Manual: MATLAB

(FALL-2020)

Submitted By:

Roll No. 2017-BET-BMED-27

Submitted To:

SIR USMAN

(Lecturer)

Biomedical Engineering Centre

University of Engineering and Technology Lahore,


KSK, Campus
Lab-02 biomedical imaging
Sumbal Zahra Ameen
2017-BET-BMED-27
LAB-02

Learning basics of matlab

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.

Figure 2: command window displays “good”


Figure 1: disp command use to display lines
Lab-02 biomedical imaging
Sumbal Zahra Ameen
2017-BET-BMED-27
2. table
Table is a data type suitable for column-oriented or tabular data that is often stored as columns in a
text file or in a spreadsheet. Tables consist of rows and column-oriented variables.
1) Initialize the variable named as “x”, which represents here angle in degree.
2) Write the command of table as the syntax shown in figure.
3) The table command will generates a table of x angles with respectively sin wave’s value.

Figure 3: a list in form of a table is formed

3. zeros
A matrix containing all elements zeros is generated here.

Figure 4: zero matrix

4. ones
A matrix containing all elements equal to one.

Figure 5: ones matrix


Lab-02 biomedical imaging
Sumbal Zahra Ameen
2017-BET-BMED-27
5. logical operators
1) Matlab also provides the usage of logical operators such as AND, NOT, NOR, OR gates.
2) Two variables a and b are assigned values, with semicolon.
3) Another variables x is assigned with two conditions that if b is not equal to zero as well as the
division of a with b is greater than 5, it will print or give an answer of true or 1,that state that this
conditions are true.

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.

Figure 10: nested for loops

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.

Figure 10: nested for loops


Lab-02 biomedical imaging
Sumbal Zahra Ameen
2017-BET-BMED-27
LAB-02 Assessment question:

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.

Figure 11: System that converts centigrade temperature into Fahrenheit

You might also like