English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
if ... endThe statement contains aifA statement and a boolean expression, followed by one or more statements. It is byendStatement Delimiters.
The syntax of if statements in MATLAB is-
if <expression> If the boolean expression is true, execute the following statements <statements> end
If the result of the expression calculation is true, execute the code block in the if statement. If the result of the expression calculation is false, execute the first group of code after the end statement.
Create a script file and input the following code-
a = 10; Check the condition using if statement if a < 20 If condition is true, print the following content fprintf('a is less than 20\n'); end fprintf('The value of a is: %d\n', a);When running the file, it displays the following result-
a is less than 20 The value of a is: 10