How t check if a value is undefined in a matrix?

832 views Asked by At

I have a matrix ratiotest:= [undef;undef;4].

Local i
Local ratiotest

for i,1,rowDim(ratiotest),1
 if ratiotest[i] = "undef" Then
  ∞→ratiotest[i]
 end if
endfor

But I get "Error: Variable is not defined"

Is there anyway to detect a undefined variable ? Im am missing something in the code ?

2

There are 2 answers

0
soegaard On BEST ANSWER

Use the construct IfFn. The fourth argument will be returned if the first argument is undefined. Therefore

IfFn(x,false, false, true) 

is true only for x being undefined.

2
fragg On

Had the same problem and soegaard's solution is not working. The only thing i could do is to transform expression into string and test it for being "undef". This piece of code will return list2, where undef elements of list1 are replaced with 0.

for i1,1,dim(list1)
    list_str:=string(list1[i1])
    list2[i1]:=iffn(list_str="undef",0,list1[i1])
endfor