Documentation Center

  • Trial Software
  • Product Updates
我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

isglobal

Determine whether input is global variable

    Note   Support for the isglobal function will be removed in a future release of the MATLAB® software. See Tips below.

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

| | |

Was this topic helpful?