我有一个矩阵 ratiotest:= [undef;undef;4]。
Local i
Local ratiotest
for i,1,rowDim(ratiotest),1
if ratiotest[i] = "undef" Then
∞→ratiotest[i]
end if
endfor
但我明白了"Error: Variable is not defined"
反正有没有检测到未定义的变量?我在代码中遗漏了什么?
我有一个矩阵 ratiotest:= [undef;undef;4]。
Local i
Local ratiotest
for i,1,rowDim(ratiotest),1
if ratiotest[i] = "undef" Then
∞→ratiotest[i]
end if
endfor
但我明白了"Error: Variable is not defined"
反正有没有检测到未定义的变量?我在代码中遗漏了什么?
使用构造IfFn
。如果第一个参数未定义,则返回第四个参数。所以
IfFn(x,false, false, true)
仅当 x 未定义时才成立。
有同样的问题,soegaard 的解决方案不起作用。我唯一能做的就是将表达式转换为字符串并测试它是否为“undef”。这段代码将返回 list2,其中 list1 的 undef 元素被替换为 0。
for i1,1,dim(list1)
list_str:=string(list1[i1])
list2[i1]:=iffn(list_str="undef",0,list1[i1])
endfor