Documentation

whos

List variables in workspace, with sizes and types

Description

example

whoslists in alphabetical order the names, sizes, and types of all variables in the currently active workspace.

example

whos -filefilenamelists variables in the specified MAT-file.

whos globallists variables in the global workspace.

example

whos___var1 ... varNlists only the specified variables. Use this syntax with any of the arguments in the previous syntaxes.

example

whos___-regexpexpr1 ... exprNlists only the variables that match the specified regular expressions.

example

S= whos(___)stores information about the variables in the structure arrayS

Note

You must use the functional form ofwhoswhen there is an output argument.

Examples

全部折叠

Display information about specific variables in the current workspace. For example, list information about variables with names that start with the lettera

whosa*

Now, list information about variables with names that end withion

whos-regexpion$

Display all the information on the variables stored in the sample MAT-filedurer.mat

whos-filedurer.mat
Name Size Bytes Class Attributes X 648x509 2638656 double caption 2x28 112 char map 128x3 3072 double

Store information about the variables indurer.matin structure arrayS

S = whos('-file','durer.mat');

Display the contents ofS

fork = 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

Create variables with various attributes, and then display information about them.

Create a file,show_attributes.m, that contains these statements.

functionshow_attributespersistentp;globalg; p = 1; g = 2; s = sparse(eye(5)); c = [4+5i 9-3i 7+6i]; whos

Callshow_attributes。When MATLAB® executes thewhoscommand at the end ofshow_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 all the variables in the current workspace while paused in a nested function.

Create a file,whos_demo.m, that contains these statements.

functionwhos_demo date_time = datestr(now,'dd-mmm-yyyy');date_time_array = strsplit(date_time,{'-',''}); get_date(date_time_array);functionget_date(d) day = d{1};%#ok<*NASGU>mon = d{2}; year = d{3}; keyboardendend

Runwhos_demo。妈TLAB®pauses at the line with thekeyboardcommand.

whos_demo
K>>

Call thewhosfunction. MATLAB displays the variables in the nestedget_datefunction, 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

全部折叠

Variables to display, specified as one or more character vectors or string scalars. Use the'*'wildcard to match patterns. For example,谁* *lists the names of all the variables in the workspace that start withAorS

Regular expressions that define the variables to display, specified as one or more character vectors or string scalars. For example,whos -regexp ^Mon ^Tueslists only the variable names in the workspace that begin withMonorTues。For more information about creating regular expressions, seeRegular Expressions

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.matlists all variables in the MAT-file namedmyFile.mat。Thewhos -filefilenamecommand does not return the sizes of any MATLAB objects in filefilename

Data Types:char|string

Output Arguments

全部折叠

Variable information, returned as a nested structure array containing a scalarstructfor each variable. Each scalarstructcontains these fields.

Field Description

name

Name of the variable.

size

Dimensions of the variable array.

bytes

Number of bytes allocated for the variable array.

whosreturns the number of bytes each variable occupies in the workspace, which is not necessarily the same as the number of bytes each variable occupies in a MAT-file. MAT-files Version 7 and later are compressed, so the number of bytes required in the workspace is typically larger than the number of bytes in the file.

whosdoes not report the number of bytes consumed by handle objects. If a variable contains handle objects, the number of bytes that thewhosfunction displays for the variable might be smaller than expected.

class

Class of the variable. If the variable has no value, class is'(unassigned)'

global

trueif the variable is global.

sparse

trueif the variable is sparse.

complex

trueif the variable is complex.

nesting

Structure with these fields:

  • function— Name of the nested or outer function that defines the variable.

  • level— Nesting level of that function.

persistent

trueif the variable is persistent.

Alternatives

  • You also can view the contents of MAT-files using the Details Panel of the Current Folder browser.

Introduced before R2006a