| Contents | Index |
| On this page… |
|---|
Viewing and Editing Values in the Workspace Improving Workspace Browser Performance Loading a Saved Workspace and Importing Data Changing and Copying Variable Names in the Workspace |
The Workspace browser provides a graphical user interface that enables you to view, change, and plot MATLAB workspace values. To open the Workspace browser, do either of the following:
Select Desktop > Workspace.
Type workspace at the Command Window prompt.
By default, the Workspace browser displays the base workspace. The Stack field enables you to view function workspaces if MATLAB is in debug mode, but otherwise appears dimmed. For more information, see Debugging Process and Features and the dbstack and evalin functions.
To generate a plot of one or more variables in the Workspace browser, use the Plot Selector tool. For more information, see Creating Plots from the Workspace Browser.

The MATLAB workspace consists of the set of variables built up and stored in memory during a MATLAB session. You add variables to the workspace by using functions, running MATLAB code, 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.
For each variable or object, the Workspace browser shows:
The name
The class (also represented by the icon)
The Value
Statistics — such as the Min, Max, and Mean calculations, when relevant
MATLAB performs these calculations using the min, max, and mean functions, and updates the results automatically.
The following table describes how to edit values and adjust columns in the Workspace browser table:
| To: | Do this: |
|---|---|
Edit variable values in the Value column | Position the pointer in the Value column at the row you want to edit, click, and then type the new value. |
View more of the data for a variable (as well as to more easily edit it) | Double-click a variable name. The variable opens in the Variable Editor. For more information, see Viewing and Editing Workspace Variables with the Variable Editor. |
Display additional columns Such as size (dimensions), size in bytes, mode and standard deviation | Select View > Choose Columns.. On Microsoft Windows systems, you can also right-click any column header. |
Specify how NaNs are considered in statistical calculations | Select File > Preferences > Workspace, and select an option for Handling NaNs when calculating statistics. |
Limit the array size for which statistics are calculated | |
Resize a column | Drag the border of the column header. |
Reorder columns | Drag a column header to a new position. |
Sort columns | 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. |
If your data includes NaNs, you can specify that the Workspace browser statistical calculations consider or ignore the NaNs. Select File > Preferences > Workspace , then select one of the following:
Use NaNs when calculating statistics
If a variable includes a NaN, and you select this option, the values for Min, Max, Var and some other statistics will appear as NaN. However, Mode, for example, shows a numeric result.
Ignore NaNs when calculating statistics
If a variable includes a NaN, and you select this option, numeric results appear for most statistics including Min and Max. Var, however, is still appears as NaN.
For more information about statistical values in the Workspace browser, see Viewing and Editing Values in the Workspace.
To list the current workspace variables, use who.
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
To list the variables and information about size and class, use whos.
For example:
>> whos Name Size Bytes Class Attributes A 4x4 128 double C 1x3 348 cell R 3x4x5 480 double
If you show statistical columns in the Workspace browser, and you work with very large arrays, you might experience performance issues when the data changes as MATLAB updates the statistical results. To improve performance, consider one or both of the following:
Show only the statistics of interest to you.
Select View > Choose Columns, and then clear the statistics you do not want MATLAB to calculate.
Exclude large arrays from statistical calculations.
Select File > Preferences > Workspace , and then use the arrow buttons to change the value of the maximum array size for which you want the Workspace browser to perform statistical calculations. Any variable exceeding the maximum array size reports <Too many elements> in Workspace browser statistics columns instead of statistical results.
The workspace is not maintained across sessions of MATLAB. When you quit MATLAB, the workspace clears. 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 in the Workspace browser:
Select File > Save Workspace As from the
Workspace browser, or click the Save button
in the Workspace browser toolbar.
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.
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 with the Current Folder Browser.
To specify preferences for saving MAT-files that pertain to compression, and compatibility between different versions of MATLAB, select File > Preferences > General > MAT-Files.
To save workspace variables, use the save function followed by the file name you want to save to. For example, to save all current workspace variables to the file june10.mat:
save('june10')
To view a MAT-file without loading it into the workspace, do one of the following:
Select the MAT-file in the Current Folder browser.
The contents display in the Details panel.
Use whos with the -file option.
You can load entire MAT-files or selected variables using one of these methods:
To load MAT-files using the desktop:
Click the Import Data button
on the toolbar in the Workspace browser.
Select the MAT-file you want to load and click Open.
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.
See also, Tips for Using the Import Wizard.
To load MAT-files programmatically
Use load.
For example, to load all workspace variables from the file june10.mat:
load('june10')
To load selected variables:
Drag them from the Current Folder browser Details panel to the Workspace browser.
To import data you previously copied to the clipboard
Select Edit > Paste to workspace, or use Ctrl+V.
MATLAB imports the clipboard data using the Import Wizard.
To rename a variable in the workspace:
Right-click the variable in the Workspace browser, and then select Rename from the context menu.
Type the new variable name over the existing name, and then press Enter.
To copy variable from the clipboard, select the workspace variables, and then 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 variables:
To select multiple variables, use Shift+click or Ctrl+click.
To select all variables, select Edit > Select All.
Press the Delete key on
your keyboard or click the Delete button
on the Workspace browser toolbar.
To delete all variables, select Edit > Clear Workspace from any desktop tool.
Use the clear function to clear variables from the workspace. For example, to clear the variables A and M from the workspace:
clear A M
Use the clearvars function with the -except option to keep specified variables and clear all other variables.
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. The following table also describes what you can accomplish with the Plot Selector and how to do it.
| To: | Do This: |
|---|---|
| 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 then 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,'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,'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 to open it in the Variable Editor. There, 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.
![]() | 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-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |