From the course: Learning MATLAB

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

If/else statements

If/else statements - MATLAB Tutorial

From the course: Learning MATLAB

If/else statements

- [Instructor] In this video and the next one we are going to cover some MATLAB functions that provide conditional programming control. If the if statement evaluates a logical expression and executes a group of statements when the expression is true, for example, if my height is smaller than my friend's then I can say that the statement, "My friend is taller than me," is true. In a new script window we are going to create a small program using if and else statements, and then else-if. Let's assume that we have to look at the temperature today and compare it with a certain reference temperature, and based on the result, we decide if it is going to be a hot or a cold day. First, we type the comment at the beginning of our program. So start with a percentage symbol, Is it going to be cold or hot today? And then we leave an empty row and start with a program. So now let's type the value of the reference temperature. Let's say…

Contents