2

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 ?

AlessioX
  • 3,167
  • 6
  • 24
  • 40
Ch32k0
  • 244
  • 3
  • 17

2 Answers2

2

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.

soegaard
  • 30,661
  • 4
  • 57
  • 106
0

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
Tony Babarino
  • 3,355
  • 4
  • 32
  • 44
fragg
  • 351
  • 1
  • 7
  • That is a great workaround, i ll test it later on and ley you know if it works! – Ch32k0 Jun 28 '16 at 18:42
  • Ok, but one more thing - if you want to check the whole matrix/list for undef elements, because you might not want to enter the loop if there isnt any, the next line will do it: `instring(string(list1),"undef")` This will return 0 if no element is undef – fragg Jun 29 '16 at 22:34