5. Atiqa Ijaz Khan Roll no. 02
5 Inst. Of Geology, PU
Question. 5:
6. Atiqa Ijaz Khan Roll no. 02
6 Inst. Of Geology, PU
Question 6:
7. Atiqa Ijaz Khan Roll no. 02
7 Inst. Of Geology, PU
Question No.7:
Question 8:
8. Atiqa Ijaz Khan Roll no. 02
8 Inst. Of Geology, PU
Question 9:
What is the difference between While and For loop. Justify your answer with example.
1. FOR LOOPS: The for statement, or the for loop, is used when it is necessary to
repeat statement (s) in a script or function, and when it is known ahead of time how many
times the statements will be repeated. The statements that are repeated are called the
action of the loop.
9. Atiqa Ijaz Khan Roll no. 02
9 Inst. Of Geology, PU
2. WHILE LOOPS: The while statement is used as the conditional loop in matlab; it is used
to repeat an action when ahead of time it is not known how many times the action will be
repeated.
Here is a while loop which divides a number by 2 over and over until the result is less than or
equal to 1. Think "while the number is greater than 1, keep dividing." Furthermore this code only
prints the final result.
10. Atiqa Ijaz Khan Roll no. 02
10 Inst. Of Geology,
PU
Question. 10:
What is the difference between matrix and structure in Matlab. Justify your answer with example.
FOR MATRIX: The dimensions of Matrix is ‘r by c’, also known as 2D array. It takes only
NUMERIC data type!
FOR STRUCTURES: A structure is a data type that groups’ related data using data containers
called fields. Each field can contain data of any type or size. A struct array has the following
properties:
1. All structs in the array have the same number of fields.
2. All structs have the same field names.
3. Fields of the same name in different structs can contain different types or sizes of data.