Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - English


exists

checks variable existence

Syntax

ve = exists(name)
ve = exists(name, where)

Arguments

name

matrix of character strings: names of queried variables.

where

an optional character with possible values: 'l' (local), 'n' (nolocal) and 'a' (all). The default value is 'a'.

ve

a matrix with the same size as name with possible values: 1 if true, 0 if false

Description

exists(name) returns 1 if the variable named name exists and 0 otherwise.

Caveats: a function which uses exists may return a result which depends on the environment!

exists(name,'l') returns 1 if the variable named name exists in the environment of the current function and 0 otherwise.

exists(name,'n') returns 1 if the variable named name exists in any level of the calling environment (including the Scilab shell main level) of the current function and 0 otherwise.

Warning: the exists function does not check if a variable exists in the global namespace.

Examples

exists("myNotLikelyToExistVar")
myNotLikelyToExistVar = 1;
exists("myNotLikelyToExistVar")
deff('foo(x)',..
['disp([exists(''a12''),exists(''a12'',''l'')])'
 'disp([exists(''x''),exists(''x'',''l'')])'])
foo(1)
a12=[];foo(1)

function level1()
  function level2()
    disp(exists(["a","b"],"a"));
    disp(exists(["a","b"],"l"));
    disp(exists(["a","b"],"n"));
  endfunction
  level2()
endfunction
function go()
  a=1;
  level1()
endfunction
go()

See also

  • isdef — checks variable existence
  • isglobal — checks if a local variable has a global counterpart
  • whereis — Returns the name of the loaded library/module a given function belongs to
  • type — returns the type of a Scilab object
  • typeof — explicit type or overloading code of an object
  • macrovar — variables of function
Report an issue
<< clearglobal Variables global >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:13:06 CEST 2024