Professional Documents
Culture Documents
Matlab Lecture 4
Matlab Lecture 4
Lecture 4
Introduction to MATLAB
1
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
PROGRAMMING
IN
MATLAB
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Programming in MATLAB
Relational Operators
• A relational operator compares two numbers by determining whether a comparison statement (e.g.,
5<8) is true or false. If the statement is true, value 1 is assigned and if the statement is wrong, value 0
is assigned.
Logical Operators
• A logical operator examines true/false statements and produces a result that is
true (1) or false (0) according to specific operator.
Order of Precedence
Parentheses
Exponential
Multiplication, Division
Addition, Subtraction
Logical OR (|)
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Conditional Statements
• The if-end Structure
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Loops
• A loop control is used to execute a set of commands repeatedly.
For Loop
• Repeats for specified number of times.
For Loop
• Example function file using for loop
While Loop
• Will do computational loop ONLY if while condition is met.
While Loop
• Example file for while loop
• In the similar way we can also place loops inside conditional statements or other loops.
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
• When inside a loop (for or while), the break command terminates the execution of loop (the
whole loop, not just the last pass).
• If the break command is inside a nested loop, only the nested loop is terminated.
• When a break command appears outside a loop in a script of function file, it terminates the
execution of the file.
• The break command is usually used within a conditional statement. In loops it provides a
method to terminate the looping process if some condition is met.