views:

358

answers:

2

How can I see a list of what global variables are defined in MATLAB? (I am using R2009a).

I have hunted unfruitfully for this on Google and SO, so apologies if it has been asked before.

+3  A: 

If you type whos at the command line Matlab will list all currently defined variables in your workspace. The last column of output is headed 'Attributes', global variables have the attribute 'global'.

High Performance Mark
Thanks but this didn't work for me! There are no globals in my the 'whos' list, yet many functions are clearly storing globals.
Sanjay Manohar
+9  A: 

The WHO/WHOS commands can show you just the global variables:

who global   %# Shows just the variable names
whos global  %# Shows variable information, like size, class, etc.

You can also get the variable names/information returned in a variable instead of displayed on the screen:

names = who('global');  %# A cell array of variable names
data = whos('global');  %# A structure array of variable information
gnovice
So it does ! +1
High Performance Mark
great, that works thanks!
Sanjay Manohar

related questions