Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list global variables in MATLAB?

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.

like image 921
Sanjay Manohar Avatar asked Apr 28 '10 17:04

Sanjay Manohar


People also ask

How can I see all global variables?

Use the env command. The env command returns a list of all global variables that have been defined. If a global variable exists in a script that hasn't been run yet, it will not show up in the output from env .

How do you show a variable list in MATLAB?

To view the variables in the workspace, use the Workspace browser. To view the contents of MAT-files, use the Details Panel of the Current Folder browser. The Details panel is not available in MATLAB Online™.

Where are global variables stored MATLAB?

All variables in MATLAB are stored in a workspace. When manipulating data at the command line, the variables are stored in the MATLAB base workspace. The contents of this workspace can be displayed by using the whos command.

Which command in MATLAB is used to list variables and their sizes?

whos lists in alphabetical order the names, sizes, and types of all variables in the currently active workspace. whos -file filename lists variables in the specified MAT-file.


2 Answers

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
like image 168
gnovice Avatar answered Oct 24 '22 22:10

gnovice


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'.

like image 39
High Performance Mark Avatar answered Oct 24 '22 23:10

High Performance Mark