| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
The workspace consists of the set of variables built up during a session of using the MATLAB software and stored in memory. You add variables to the workspace by using functions, running M-files, and loading saved workspaces. For example, if you run these statements,
A = magic(4) R = randn(3,4,5)
the workspace includes two variables, A and R.
You can perform workspace and related operations using the Workspace browser. When available, equivalent functions are documented with each feature of the Workspace browser.
To open the Workspace browser, select Desktop > Workspace in the MATLAB desktop, or type workspace at the Command Window prompt.
The Workspace browser opens.

You can specify which buttons you want to appear on the toolbar using preferences. Select File > Preferences > Toolbars to open the dialog box. Click Help for information using the dialog box.
The Workspace browser shows the name of each variable or object, the class (also represented by the icon), its value, and where relevant, the Min, Max, and Mean calculations. MATLAB performs these calculations using the min, max, and mean functions, and updates the results automatically. These are other features of the Workspace browser:
You can display additional columns, including size (dimensions), size in bytes, and other common statistical calculations such as mode and standard deviation. To show or hide columns, select View > Choose Columns. On Microsoft Windows systems, you can right-click any column header to hide it or to show or hide other columns. To specify the size limit for calculations and how NaNs are considered, use Setting Workspace Browser Preferences.
To resize a column of information, drag the column header border. To reorder columns, drag a column header to a new position.
You can select the column on which to sort as well as reverse the sort order of any column. Click a column header to sort on that column. Click the column header again to reverse the sort order in that column. For example, to sort on Name, click the column header once. To change from ascending to descending, click the header again. You cannot sort by the Value column in the Workspace browser.
You can directly edit variable values in the Workspace browser Value column. To edit a value, position the pointer in the Value column at the row you want to edit, click, and type the new value.
To view more of the data for a variable, as well as to more easily edit it, double-click a variable name and it opens in the Variable Editor. For more information, see Viewing and Editing Workspace Variables with the Variable Editor.
Use who to list the current workspace variables. Use whos to list the variables and information about size and class. For example:
>> who Your variables are: A S avg_score names scores v y C a b nn t w1 z R ans l s1 td x >> whos Name Size Bytes Class Attributes A 4x4 128 double C 1x3 348 cell R 3x4x5 480 double S 1x3 826 struct a 4x4 128 double ans 3x4x5 480 double avg_score 1x1 8 double b 4x4 128 double l 4x4 16 logical names 3x12 72 char nn 3x3 72 double s1 1x1 4 single scores 1x3 24 double t 1x5 10 char td 1x1 152 TensileData v 2x5 20 char w1 1x1 16 double complex x 1x1 2 int16 y 1x3 12 uint32 z 1x1 8 double
Use exist to see if the specified variable is in the workspace.
The workspace is not maintained across sessions of MATLAB. When you quit MATLAB, the workspace is cleared. You can save any or all of the variables in the current workspace to a MAT-file, which is a binary file specifically for use in MATLAB. You can then load the MAT-file at a later time during the current or another session to reuse the workspace variables. MAT-files use a .mat extension.
Note The .mat extension is also used by Microsoft Access application. You can change the default file association in the Microsoft Windows operating system to associate MAT-files with either MATLAB or the Access application. |
To save all of the workspace variables using the Workspace browser:
Select File > Save Workspace As from the
Workspace browser, or click the Save button
in the Workspace browser toolbar.
The Save to MAT-File dialog box opens.
Specify the location and File name. MATLAB automatically supplies the .mat extension.
The workspace variables are saved under the MAT-file name you specified.
To save some but not all of the current workspace variables:
Select the variable in the Workspace browser. To select multiple variables, Shift+click or Ctrl+click.
Right-click, and from the context menu, select Save As.
The Save to MAT-File dialog box opens.
Specify the location and File name. MATLAB automatically supplies the .mat extension.
The workspace variables are saved under the MAT-file name you specified.
Another way to save selected variables from the Workspace browser to a MAT-file is by dragging the selected variables from the Workspace browser to the Current Folder browser. For more information, see Creating and Updating MAT-Files.
To specify preferences for saving MAT-files that pertain to compression, and compatibility between different versions of MATLAB, see MAT-Files Preferences.
To save workspace variables, use the save function followed by the filename you want to save to. For example,
save('june10')
saves all current workspace variables to the file june10.mat.
If you don't specify a filename, the workspace is saved to matlab.mat in the current folder. You can specify which variables to save, as well as control the format in which the data is stored, such as ASCII. For these and other forms of the function, see the reference page for save. MATLAB provides additional functions for saving information — see Exporting Data.
You can view saved variables and load the variables and other data into the workspace using the Current Folder browser, the Import Wizard, or the load function.
Use the Current Folder browser to view the contents of a MAT-file without loading the file into MATLAB. You can also load selected variables by dragging them from a MAT-file in the Current Folder browser to the Workspace browser. For details, see Viewing Details About Files and Folders In the Current Folder Browser.
Function Alternative. Use whos with the -file option.
MATLAB provides an Import Wizard to load MAT-files and other forms of data into the workspace. This procedure briefly describes how to use the Import Wizard from the Workspace browser to import data from MAT-files.
Click the Import Data button
on the toolbar in the Workspace browser.
The Import Data dialog box opens.
Select the MAT-file you want to load and click Open.
The variables and their values, as stored in the MAT-file, are loaded into the current workspace. Any variables in the MAT-file that are not in the workspace are added to the workspace. If any variables being loaded have the same names as variables in the current workspace, MATLAB asks if you want to replace the values in the current workspace with the values in the MAT-file, or cancel.
You can also use the Workspace browser to import data you previously copied to the clipboard by selecting Edit > Paste to workspace, or use Ctrl+V. This imports the clipboard data using the Import Wizard.
For more information about the Import Wizard, see Using the Import Wizard.
Use load to open a saved workspace. For example,
load('june10')
loads all workspace variables from the file june10.mat.
To rename a variable in the workspace, right-click the variable in the Workspace browser and select Rename from the context menu. Type the new variable name over the existing name and press Enter.
To copy variable names to the clipboard, select the workspace variables and select Edit > Copy. You can then paste the names, for example, into the Command Window. Multiple variables are comma separated.
You can delete a variable, which removes it from the workspace:
In the Workspace browser, select the variable, or Shift+click or Ctrl+click to select multiple variables. To select all variables, choose Select All from the Edit or context menus.
Press the Delete key on
your keyboard or click the Delete button
on the Workspace browser toolbar.
A confirmation dialog box might appear. If it does, click OK to clear the variables.
The confirmation dialog box appears if you selected that preference. For more information, see Confirmation Dialogs Preferences.
To delete all variables, select Edit > Clear Workspace from any desktop tool.
Use the clear function to clear variables from the workspace. For example,
clear A M
clears the variables A and M from the workspace.
Use the clearvars function with the -except option to keep the specified variables and clear all other variables.
When you run M-files, MATLAB assigns each function its own workspace, called the function workspace, which is separate from the base workspace in MATLAB. To access the base and function workspaces when debugging M-files, use the Stack field in the Workspace browser. The Stack field is only available in debug mode and otherwise appears dimmed. The Stack field is also accessible from the Editor and the Variable Editor. For more information, see Finding Errors, Debugging, and Correcting M-Files. See also the dbstack and evalin functions.
You can generate a plot of one or more variables with the Plot
Selector tool
on the Workspace browser toolbar.
(The appearance of the tool varies, depending on the variables you
select and your history of using it.) The Plot Selector contains menu
items identifying plotting functions available to you and executes
them when you click the graph icons. The following steps illustrate
how the tool works:
Create two vector variables:
run = 0:.1:4*pi; wave = (sin(run.^2) + cos(run).^2);
Select one or both variables in the Workspace Browser. You can Shift+click or Ctrl+click to select multiple variables to plot as x, y, or z components of a graph.

Click the down arrow icon in the Plot Selector on the toolbar. The Plot Selector menu opens.

Scroll to the graph type you want to display and click the icon on its left side. The icon highlights when you hover over it.

A figure window opens with a graph of the selected variable or variables, using the plotting function you just chose.

The Plot Selector GUI remains open until you click a desktop component or another window. This enables you to experiment with plot types without reopening the GUI each time.
You can interact with the Plot Selector in many ways. Learn about using it by viewing this video demo. Also, read the following table to better understand what you can accomplish with the Plot Selector and how to do it.
| What You Can Do | How To Do It |
|---|---|
| Identify variables to graph. | Select a variable of numeric type in the Workspace Browser. To add variables to your selection, Shift+click or Ctrl+click. |
| Plot selected variables immediately using the default graph type. | Click the Plot Selector icon; a graph of the type it displays will plot using the selected variables. |
| Plot selected variables after choosing a graphing function. | Click the arrow
|
| Interchange two variables before graphing them. | Click the Reverse Input Variable Order button
|
| Identify the graphing functions you can currently use to create a plot. | With one or more selected variables, select the first tab, Plots
for:<variables>
|
| Identify available graphing functions. | With zero or more variables selected, select the second tab, All
plots
|
| Add a graph type to Favorites. | In either tab:
All of these actions create a copy the item in Favorites without removing it from its category. |
| Remove a graph type from Favorites. | In the Favorites category of either tab
do either of the following:
You cannot drag a menu item out of Favorites. |
| Change the order of menu items within a category. | Click a menu item outside the graph icon and drag it to a new position within its category. |
| Move a menu item to a different category. | Click a menu item outside the graph icon and drag it to a new category. Dragging an item away removes that item from the category it was in. This gesture does not apply to items within Favorites. |
| Get help for a graphing function. | On either tab, hover mouse pointer over a menu item. A syntax description pops up next to the item. To see the complete function reference page, click the More Help link in the description header. |
| Enable a dimmed menu item. | Select one or more variables appropriate for calling the dimmed function. Then, open the Plot Selector tool again. See Selecting Appropriate Variables and Determining What Inputs a Graphing Function Needs. |
| Manually execute or modify a plotting call. | Drag a menu item (even if it is dimmed) to the Command Window or the Editor; the code for that plot displays and you can edit it. See Editing a Plot Selector Graphing Command. |
| Display the Plot Selector as a window. | Open the Plot Selector, click the grab bar
|
| Access the Plot Catalog. | Click the Catalog link at the bottom of the Plot Selector tool. |
If you select insufficient or inappropriate variables for a graph type, its menu item is dimmed on the All plots Plot Selector tab. The dimmed items do not appear at all on the Plots for: tab. Dimmed and missing Plot Selector menu items indicate that you cannot use the function for plotting the selected data via the tool. Reasons why a function is not available include:
You selected a variable having the wrong class for graphing (it is not a numeric type).
The graphing function requires additional inputs (for example, scatter requires two vectors).
The graphing function requires fewer inputs than you selected (for example, plot cannot handle three vectors)
Your selected variable has inappropriate type or dimensions (for example, matrices displayed by feather must be complex).
You selected variables in the wrong order (for example, selecting scalar n and then matrix Z to contour(n,Z) instead of contour(Z,n)).
If you select variables that no function can display,
the Plot Selector button label changes to No valid plots
for:<variable>
. If you click the button,
you see the message "No plot available for selection. Change
your variable selection or click the All plots tab
to browse for plots."
When a Plot Selector menu item is unavailable (dimmed) in the All plots tab, you can learn why by viewing the pop-up help for that function. Suppose you want to make a semilogy graph.
In the All plots tab, you can do several different things:
Create a nonnumeric variable, for example, a string.
name = 'abcd';
Select name in the Workspace Browser and open the Plot Selector tool by clicking its down arrow.
Click the All plots tab in the Plot Selector window.
Scroll to the semilogy menu item (all items are dimmed) and hover the mouse pointer over the item.
A help message appears that includes a note specifying what inputs the semilogy function accepts. The pop-up help window contains a white box that describes the function's input requirements, as shown in the following figure.

The message helps you to understand what arguments the semilogy function supports.
A Help Window opens whenever your mouse pointer lingers over a menu item, but information set off in a white box only appears when the function is dimmed because it cannot generate a graph of the currently selected variables.
Even when the Plot Selector tool cannot successfully make a graph, it can still give you a starting point for doing so. You can drag any Plot Selector menu item into the Command Window to see the code it generates. Once the plotting command displays in the Command Window, it does not execute until you press Enter, enabling you to edit its arguments first. Dragging dimmed items works the same as dragging undimmed items. This enables you to fix problems due to selecting the wrong variables or selecting them in the wrong sequence. You can also add arguments to the plotting command, for example to specify a linespec or a colorspec for functions that can use them.
The following example illustrates how to drag a dimmed Plot Selector menu item, drop it into the Command Window, and edit the plotting command before executing it.
In the Command Window, enter
alist = '1 2 3 4 5 6 7 8 9 10'; ilist = [1 2 3 4 5 6 7 8 9 10];
Assume that you want to create a graph of ilist but instead you select the string variable alist in the Workspace Browser. When you click the Plot Selector, it displays this error message.

You can go on to plot ilist by continuing as follows.
Click the All Plots tab and scroll to semilogy. The menu item is dimmed.
Press the mouse button over semilogy and drag it to the command window, as shown here.

Release the mouse button in the Command Window The following line of code appears there:
>> semilogy(alist,'DisplayName','alist');figure(gcf)
If you press Enter, an error displays because alist is not a proper calling argument:
??? Error using ==> semilogy Invalid first data argument
Instead, change the code to the following, substituting ilist for alist:
semilogy(ilist,'DisplayName','ilist');figure(gcf)
This call works with the changed arguments and generates the following graph after you press Enter.

You can also edit the plotting command to add other arguments, including parameter/value pairs, to customize the graph.
If you want to use the Plot Selector to create a graph for a subrange of a vector or a matrix, you can open the variable in the Variable Editor, select the range of data you want to graph, and open the Plot Selector from the Variable Editor toolbar. All data for the graph must all come from one variable and the subrange to plot has to be a contiguous selection.
You can add titles, axis labels, legends and other annotations to graphs that the Plot Selector makes. For more information about graphing data and customizing plots, see the following topics in the MATLAB Graphics documentation:
In the Workspace browser, double-click a variable and it opens in the Variable Editor where you can view and edit the contents of the variable. See Viewing and Editing Workspace Variables with the Variable Editor for more information.
Some toolboxes allow you to double-click an object in the Workspace browser to open a viewer or other tool appropriate for that object. For details, see the toolbox documentation for that object type.
The Workspace browser displays statistical calculations for variables. Use preferences to restrict the size of arrays on which you perform calculations and to specify if you want those calculations to include or ignore NaNs. Select File > Preferences > Workspace to open the dialog box. Make your changes and click OK.

If you show statistical columns in the Workspace browser, and if you work with very large arrays, you might experience performance issues when the data changes as MATLAB updates the statistical results. In that event, show only the columns of interest to you and hide those you do not need.
Another step you can take is specify via a preference that the Workspace browser not perform statistical calculations on the largest arrays. Use the arrows to change the value of the maximum array size for which you want the Workspace browser to perform statistical calculations. The default value is 500,000 elements. Any variable exceeding that size reports <Too many elements> instead of statistical results.
If your data includes NaNs, you can specify that the statistical calculations consider the NaNs or ignore the NaNs. For example, if a variable includes a NaN and the preference is set to Use NaNs when calculating statistics, the values for Min, Max, Var and some others will appear as NaN, although Mode, for example, shows a numeric result. With the preference set to Ignore NaNs whenever possible, numeric results appear for most of the statistical columns including Min and Max; Var, however, is still reported as NaN.
For more information about statistical values in the Workspace browser, see Viewing and Editing Values in the Current Workspace.
![]() | Workspace Browser and Variable Editor | Viewing and Editing Workspace Variables with the Variable Editor | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |