Documentation

isglobal

(To be removed) Determine if input is global variable

    Note   isglobal has been removed. Avoid conditions in your code that check variable scope.  If you need to convert your code quickly in the short term, replace isglobal with ~isempty(whos('global','variable')).  However, you should refactor your code to avoid conditional checks on variable scope.

Syntax

tf = isglobal(A)

Description

tf = isglobal(A) returns logical 1 (true) if A has been declared to be a global variable in the context from which isglobal is called, and logical 0 (false) otherwise.

More About

expand all

Tips

isglobal is most commonly used in conjunction with conditional global declaration. An alternate approach is to use a pair of variables, one local and one declared global.

Instead of using

if condition
   global x
end

x = some_value

if isglobal(x)
   do_something
end

You can use

global gx
if condition
   gx = some_value
else
   x = some_value
end

if condition
   do_something
end

If no other workaround is possible, you can replace the command

isglobal(variable)

with

~isempty(whos('global','variable'))

See Also

| | |

Introduced before R2006a

Was this topic helpful?