【正文】
B 自動(dòng)產(chǎn)生的,第二個(gè)警告訊息則是我們的程式碼產(chǎn)生的,其中 isnan(x) 可用於判斷 x 是否為 NaN,若是,則傳回 1(真),否則即傳回 0(偽)。, i, y(i))。 end end y(1) = 0 is even. y(2) = 3 is odd. y(3) = 4 is even. y(4) = 1 is odd. y(5) = 6 is even. ? 上述的 ifelse 為雙向條件,亦即程式只會(huì)執(zhí)行「運(yùn)算式一」或「運(yùn)算式 二」,不會(huì)有第三種可能。y(%g)=%g is 3n.\n39。, i , y(i))。 end end y(1)=3 is 3n. y(2)=4 is 3n+1. y(3)=5 is 3n+2. y(4)=9 is 3n. y(5)=2 is 3n+2. MATLAB 程式設(shè)計(jì)入門篇:程式流程控制 switchcaseotherwise 條件指令 ? MATLAB 在第五版開始支援 switchcaseotherwise 的多向條件指令,其使用語法如下: switch expression case value(1) statement(1) case value(2) statement(2) … case value(n1) statement(n1) otherwise statement(n) end ? 在上述語法中, expression 為一數(shù)值或字串,當(dāng)其值和 value(k) 相等時(shí),MATLAB 即執(zhí)行 statement(k) 並跳出 switch 指令。 case {6,7,8} season = 39。 case {12,1,2} season = 39。, month, season)。Feb39。Apr39。Jun39。Aug39。 for i = 1:length(month) switch month{i} case {39。,39。 case {39。,39。 case {39。,39。 case {39。,39。 end fprintf(39。 ? 一般而言, switch–case–otherwise 的執(zhí)行效率優(yōu)於 if–else 。, month{i}, season)。} season = 39。,39。} season = 39。,39。} season = 39。,39。} season = 39。,39。Sep39。Jul39。May39。Mar39。Jan39。 end fprintf(39。 case {9,10,11} season = 39。 MATLAB 程式設(shè)計(jì)入門篇:程式流程控制 程式流程控制之範(fàn)例十一 ? 欲根據(jù)月份來判斷其季別,可輸入如下: ? 範(fàn)例 1611 : for month = 1:12 switch m