Skip to Main Content Skip to Search
Product Documentation

MATLAB Workspace Browser

About the Workspace Browser

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:

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.

About the Workspace

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.

Viewing and Editing Values in the Workspace

For each variable or object, the Workspace browser shows:

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

See Improving Workspace Browser Performance.

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.

Include or Exclude NaN Values in Statistical Calculations

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:

For more information about statistical values in the Workspace browser, see Viewing and Editing Values in the Workspace.

Function Alternative

Improving Workspace Browser Performance

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:

Saving the Current Workspace

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.

Saving All Variables

To save all of the workspace variables in the Workspace browser:

  1. Select File > Save Workspace As from the Workspace browser, or click the Save button in the Workspace browser toolbar.

  2. Specify the location and File name.

  3. Click Save.

Saving Selected Variables

To save some but not all of the current workspace variables:

  1. Select the variable in the Workspace browser. To select multiple variables, Shift+click or Ctrl+click.

  2. Right-click, and from the context menu, select Save As.

  3. Specify the location and File name.

  4. Click Save.

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.

Specifying the Format When Saving MAT-Files

To specify preferences for saving MAT-files that pertain to compression, and compatibility between different versions of MATLAB, select File > Preferences > General > MAT-Files.

Function Alternative

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

Viewing a Saved Workspace

To view a MAT-file without loading it into the workspace, do one of the following:

Loading a Saved Workspace and Importing Data

You can load entire MAT-files or selected variables using one of these methods:

Changing and Copying Variable Names in the Workspace

To rename a variable in the workspace:

  1. Right-click the variable in the Workspace browser, and then select Rename from the context menu.

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

Deleting Workspace Variables

You can delete a variable, which removes it from the workspace:

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

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

Function Alternative

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.

Creating Plots from the Workspace Browser

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:

  1. Create two vector variables:

    run = 0:.1:4*pi;
    wave = (sin(run.^2) + cos(run).^2);
    
  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.

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

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

Working with the Plot Selector GUI

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 to the right of the Plot Selector button. The GUI opens for you to choose a graph type. Create plot by clicking the chosen item's picture icon.
Interchange two variables before graphing them.Click the Reverse Input Variable Order button . The two function arguments the item displays interchange. The button appears only when you select two variables.
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> and do either of the following:
  • Scroll through the menu or navigate through it with up/down arrow keys.

  • Enter a search term in the search bar; only those menu items and categories containing the search string will display.

Identify available graphing functions.With zero or more variables selected, select the second tab, All plots and do either of the following:
  • Scroll through the menu or navigate through it with up/down arrow keys

  • Enter a search term in the search bar; only those menu items and categories containing the search string display

Add a graph type to Favorites.In either tab:
  • Click the star to the right of a menu item and do any of the following:

  • Right-click a menu item and select Add to Favorites.

  • Right-click a menu item and select Copy, and then right-click within Favorites and select Paste.

  • Drag a menu item from its category to Favorites.

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:
  • Click the star at the right side of a menu item

  • Right-click a menu item and select Remove Favorite

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 at the center top, and drag the GUI to where you want it on the screen. That window closes if you click another MATLAB window. The window remains open if you focus on a window of another application.
Access the Plot Catalog.Click the Catalog link at the bottom of the Plot Selector tool.

Selecting Appropriate Variables

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:

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

Determining What Inputs a Graphing Function Needs

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:

  1. Create a nonnumeric variable, for example, a string.

    name = 'abcd';
  2. Select name in the Workspace Browser and open the Plot Selector tool by clicking its down arrow.

  3. Click the All plots tab in the Plot Selector window.

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

Editing a Plot Selector Graphing Command

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.

  1. 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];
  2. 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.

  3. Click the All Plots tab and scroll to semilogy. The menu item is dimmed.

  4. Press the mouse button over semilogy and drag it to the command window, as shown here.

  5. 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
  6. 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.

For More Information

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:

Opening Variables and Objects for Viewing and Editing

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.

  


Recommended Products

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