Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a variable is defined in Octave?

When writing a script that loads data, it's a waste of time to wait for it to load each time.

How to check to see if the variable is defined?

like image 821
B Seven Avatar asked Dec 17 '11 04:12

B Seven


2 Answers

You can use the exist function in Octave to do the work. It can be used to check the existence of given name as a variable, built in function, file, or directory. In you case, to check the existence of a variable, you may use something like this:

if (exist("your_var_name", "var") == 1)
    printf("varname exists");
else
    printf("varname not exists");
endif

You may refer the following links for detailed information:

  • Built-in Function: exist (name, type)
  • Status of Variables
like image 180
Jomoos Avatar answered Nov 03 '22 04:11

Jomoos


Need to put the variable name in quotes too,

exist("varname", "var")

like image 37
charles.fox Avatar answered Nov 03 '22 04:11

charles.fox