Matlab 使用超过1&&;操作人员
如果我有一个有两个输入的函数,除了嵌套的If函数外,有没有其他方法来测试它的两个范围 例如Matlab 使用超过1&&;操作人员,matlab,Matlab,如果我有一个有两个输入的函数,除了嵌套的If函数外,有没有其他方法来测试它的两个范围 例如 if input1 > 0 && input1 <10 && input2 > 0 && input2 <10 if-input1>0&&input10&&input20&&input10&&input2我不知道如何避免嵌套的if函数,但可以避免重复: 在JavaScript中: function test(argument1,ar
if input1 > 0 && input1 <10 && input2 > 0 && input2 <10
if-input1>0&&input10&&input20&&input10&&input2我不知道如何避免嵌套的if函数,但可以避免重复:
在JavaScript中:
function test(argument1,argument2) {
check = 0;
for (i=0;i<arguments.length;i++){
if (arguments[i] > 0 && (arguments[i] < 10)) {
check++;
if (check === arguments.length) {
//do something
}
}
}
}
test(1,2);
功能测试(argument1、argument2){
检查=0;
对于(i=0;i0&&(参数[i]<10)){
check++;
if(check==arguments.length){
//做点什么
}
}
}
}
试验(1,2);
在Matlab中尝试以下操作:
find((input1==1:20),1)&find((input2==50:100),1)
为什么第一个表达式不起作用?这两个表达式之间没有区别,除非您想在if语句之间编写更多的代码。我想您可能是说这对&&
运算符的行为“不起作用”。例如,如果input1>0
返回false
,则不会计算任何其他条件。这不一定“更简单”,但类也可以用于这些事情。这就像通过集成证明1=1。
function test(argument1,argument2) {
check = 0;
for (i=0;i<arguments.length;i++){
if (arguments[i] > 0 && (arguments[i] < 10)) {
check++;
if (check === arguments.length) {
//do something
}
}
}
}
test(1,2);