MATLAB if 語(yǔ)句語(yǔ)法
在MATLAB中 的 if 語(yǔ)句的語(yǔ)法是:
if <expression> % statement(s) will execute if the boolean expression is true <statements> end
表達(dá)式的計(jì)算結(jié)果如果是“true”,那么在代碼塊中,如果語(yǔ)句會(huì)被執(zhí)行。如果表達(dá)式計(jì)算結(jié)果為“false”,那么第一套代碼結(jié)束后的語(yǔ)句會(huì)被執(zhí)行。
MATLAB if 語(yǔ)句流程圖:

詳細(xì)例子如下:
在MATLAB中建立一個(gè)腳本文件,并輸入下述代碼:
a = 10; % check the condition using if statement if a < 20 % if condition is true then print the following fprintf('a is less than 20 ' ); end fprintf('value of a is : %d ', a);
運(yùn)行該文件,顯示下述結(jié)果:
a is less than 20 value of a is : 10
更多建議: