嵌套if语句的语法如下:if <expression 1> Executes when the boolean expression 1 is true if <expression 2> Executes when the boolean expression 2 is true end end 例如:创建脚本文件并在其中键入以下代码 :a = 100;b = 200;check the boolean condition if( a == 100 )if condition i...
方法二: 用~exist()来检测是否定义了变量。这个函数可以用来检测是否定义了变量,如果没有定义,我们可以定义。 这时上面的函数可以改写为: function c = product(a,b) if ~exist('b','var') b = 1; end c = a*b; end 这个时候我们就可以完成对b设置默认值。但是我们还可以进一步改进:例如函数有a,b,c...
isExist(x,m)返回0或1