whos
List variables in workspace, with sizes and types
Syntax
Description
whos
lists in alphabetical order the names,
sizes, and types of all variables in the currently active workspace.
whos global
lists variables in the global
workspace.
whos ___
lists
only the specified variables. Use this syntax with any of the arguments in the
previous syntaxes.var1 ... varN
whos ___ -regexp
lists only the variables that match the specified regular expressions.expr1 ... exprN
Examples
Display Workspace Variable Information
Display information about specific variables in the current workspace. For example, list information about variables with names that start with the letter a
.
whos a*
Now, list information about variables with names that end with ion
.
whos -regexp ion$
Display Information on Variables Stored in a MAT-File
Display all the information on the variables stored in the sample MAT-file durer.mat
.
whos -file durer.mat
Name Size Bytes Class Attributes X 648x509 2638656 double caption 2x28 112 char map 128x3 3072 double
Store Variable Information in a Structure Array
Store information about the variables in durer.mat
in structure array S
.
S = whos('-file','durer.mat');
Display the contents of S
.
for k = 1:length(S) disp([' ' S(k).name ... ' ' mat2str(S(k).size) ... ' ' S(k).class]); end
X [648 509] double caption [2 28] char map [128 3] double
Display Variable Attribute Information
Create variables with various attributes, and then display information about them.
Create a file, show_attributes.m
, that contains these statements.
function show_attributes persistent p; global g; p = 1; g = 2; s = sparse(eye(5)); c = [4+5i 9-3i 7+6i]; whos
Call show_attributes
. When MATLAB® executes the whos
command at the end of show_attributes
, it lists each variable and its corresponding attribute.
show_attributes
Name Size Bytes Class Attributes c 1x3 48 double complex g 1x1 8 double global p 1x1 8 double persistent s 5x5 128 double sparse
List Workspace Variables Within Nested or Anonymous Function
List all the variables in the current workspace while paused in a nested function.
Create a file, whos_demo.m
, that contains
these statements.
function whos_demo date_time = datestr(now,'dd-mmm-yyyy'); date_time_array = strsplit(date_time,{'-',''}); get_date(date_time_array); function get_date(d) day = d{1}; %#ok<*NASGU> mon = d{2}; year = d{3}; keyboard end end
Run whos_demo
. MATLAB® pauses at
the line with the keyboard
command.
whos_demo
K>>
Call the whos
function. MATLAB displays
the variables in the nested get_date
function,
and the variables in all functions that contain the nested function,
grouped by function workspace.
K>> whos
Name Size Bytes Class Attributes ---- whos_demo/get_date --------------------------------------- d 1x3 354 cell day 1x2 4 char mon 1x3 6 char year 1x4 8 char ---- whos_demo ------------------------------------------------ date_time 1x11 22 char date_time_array 1x3 354 cell
Input Arguments
var1 ... varN
— Variables to display
character vectors | string scalars
Variables to display, specified as one or more character vectors or string
scalars. Use the '*'
wildcard to match patterns. For
example, whos A* S*
lists the names of all the variables
in the workspace that start with A
or
S
.
expr1 ... exprN
— Regular expressions
character vectors | string scalars
Regular expressions that define the variables to display, specified as one
or more character vectors or string scalars. For example, whos
-regexp ^Mon ^Tues
lists only the variable names in the
workspace that begin with Mon
or Tues
.
For more information about creating regular expressions, see Regular Expressions.
filename
— Name of MAT-file
character vector | string scalar
Name of MAT-file, specified as a character vector or string scalar. The file name can include
the full, relative, or partial path. For example, whos -file
myFile.mat
lists all variables in the MAT-file named
myFile.mat
. The whos -file
command does not
return the sizes of any MATLAB objects in file filename
filename
.
Data Types: char
| string
Output Arguments
S
— Variable information
nested structure array
Variable information, returned as a nested structure array containing
a scalar struct
for each variable. Each scalar struct
contains
these fields.
Field | Description |
---|---|
| Name of the variable. |
| Dimensions of the variable array. |
| Number of bytes allocated for the variable array.
|
| Class of the variable. If the variable has no value,
class is |
|
|
|
|
|
|
| Structure with these fields:
|
|
|
Alternatives
You also can view the contents of MAT-files using the Details Panel of the Current Folder browser. The Details panel is not available in MATLAB Online™.
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)