Viewing and Editing Workspace Variables with the Variable Editor

About the Variable Editor

Use the Variable Editor to view and edit a visual representation of one or two-dimensional arrays, cell arrays, structures, and objects and their properties. You can also view the contents of multidimensional arrays.

Opening the Variable Editor

To open the Variable Editor from the Workspace browser, perform these steps:

  1. In the Workspace browser, select the variable you want to open. Use Shift+click or Ctrl+click to select multiple variables, or use Ctrl+A to select all variables to open.

  2. Click the Open Selection button on the toolbar. For one variable, you can also open it by double-clicking it.

    The Variable Editor opens, displaying the values for the selected variable. The class and size of the value appear below the toolbar, and for some classes, include a link to the help for that class.

    Image of Variable Editor showing key features. Edit the content of an element by typing in the field. Use document tabs to access other variables open in the Variable Editor.

Repeat the steps to open additional variables in the Variable Editor. Access each variable via its tab at the bottom of the window, or use the Window menu.

Changes you make to variables via the Command Window or other operations automatically update the information for those variables in the Variable Editor.

Function Alternatives

To open a variable in the Variable Editor, use openvar with the name of the variable you want to open as the argument. For example, type

openvar('A')

MATLAB opens A in the Variable Editor.

To see the contents of a variable in the workspace, just type the variable name at the Command Window prompt. For example, type

A

and MATLAB returns

A =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

Viewing and Editing Cell Arrays, Structures, Objects, and Multidimensional Arrays in the Variable Editor

Cell Arrays — Viewing and Editing in the Variable Editor

You can view and edit the content of cell arrays in the Variable Editor. In the Variable Editor, double-click an element of a cell array to open it as its own Variable Editor document. You can then view and edit the contents of that element. The following illustrations show an 1-by-3 cell array, C, and the contents of C{1,1}. When viewing an element in a cell array, for example, C{1,1}, use the Up button to go to its cell array, for this example, C.

Image of Variable Editor showing C, a 1-by-3 cell array. C{1,1} appears as a 4-by-4 double. When you double-click that cell, it opens in another document, showing its contents.

Image of Variable Editor showing C{1,1}, a 4-by-4 double in its own document in the Variable Editor.

Structures — Viewing and Editing in the Variable Editor

You can view and edit the content of structures in the Variable Editor. In the Variable Editor, double-click an element of a structure to open it as its own Variable Editor document. The following illustrations show a 1-by-3 structure, S and the result of double-clicking S(1,2), which displays the contents in its own new document.

Image of Variable Editor showing S, a 1-by-3 structure. S(1,2) is a 1-by-1 structure element. When you double-click S(1,2), it opens in another document, showing its contents in a display similar to that found in the Workspace browser.

The information shown for the element of the structure is similar to that shown in the Workspace browser: Field, Value, Size and other information. Right-click a column header to show or hide columns. Click a column header to sort by that column, and click again to reverse the sort order. When viewing an element in a structure, for example, S(1,2), use the Up button to view the structure, for this example, S. This can help you navigate in the Variable Editor when there are many variables open.

To edit the value for an element, you can click the value and make changes. Or double click the value; a new Variable Editor document opens where you can click and then make the changes. The following illustration shows the result of double-clicking the grade field for S(1,2), where you can change its value. You can use the Up button go up from the field to view the element. For example, when viewing S(1,2).grade, click the Up button to view S(1,2).

Image of Variable Editor showing the grade field for S(1,2), in its own document in the Variable Editor.

Objects and Their Properties — Viewing and Editing in the Variable Editor

Viewing Object Properties in the Variable Editor.   In the Variable Editor, you can view and edit properties of objects created with MATLAB Version 7.6 (R2008a) or higher. When you open an object in the Variable Editor, it displays Property, Value, Size, and other information. Right-click a column header to show or hide columns. Click a column header to sort by that column, and click again to reverse the sort order. The following illustration shows the td object in the Variable Editor.

Image of Variable Editor showing the td object.

Alternatively, double-click the value, which displays the value in its own document where you can more easily view and edit it. The following illustration shows the td.Material property value opened in its own document. When viewing a property, use the Up button to view the object, for this example, td. This can help you navigate in the Variable Editor when there are many variables open.

Image of Variable Editor showing the Material value for the td object opened in its own document and being edited.

Additional icons, images of locks, denote protected and private properties of an object, indicating you cannot edit the values. The following illustration shows an MException object, ME, with the private properties identifier and message.

Editing Property Values in the Variable Editor.   To edit a property's value, click the value field and make changes, as shown in the following illustration.

Image of Variable Editor showing the Material value for the td object being edited.

Getting Help for Objects and Properties from the Variable Editor.   For most classes supplied by The MathWorks™, when you click the link to the class name, for example, char, the reference page help appears in the Help browser. For user-created classes and for any other classes without a reference page, M-file help displays in the Help browser, if available.

Multidimensional Arrays — Viewing in the Variable Editor

You can view the contents of multidimensional arrays in the Variable Editor. When you open a multidimensional array in the Variable Editor, it does not have usual grid structure, because multidimensional arrays do not fit that format. You cannot double-click an element in a multidimensional array to edit it. The following illustration shows R = rand(3,4,5) opened in the Variable Editor.

Image of Variable Editor showing the 3-D array R.

Navigating and Editing Shortcut Keys for the Variable Editor

Use the following shortcut keys (sometimes called hot keys) to move among elements in the Variable Editor. Navigating in the Variable Editor is much like navigating in the Microsoft® Excel® application.

Key

Result

Enter

Commit any changes to the element and move to next element, where next element is specified using Preferences for the Variable Editor (default is down)

Tab

Move right

Within a selection, also moves from the last column to the first column in the next row

Shift+Enter or Shift+Tab

Move in opposite direction of Enter or Tab

Page Up

Move up m rows, where m is the number of visible rows

Page Down

Move down m rows, where m is the number of visible rows

Home

Move to column 1

Ctrl+Home

Move to row 1, column 1

Shift+Home

Select to column 1

End

Move to last column in current row

F2 (Ctrl+U on Apple® Macintosh® platforms)

Edit current element, positioning cursor at the end of the element

Changing Size, Content, and Format of Variables in the Variable Editor

To increase the size of an array, scroll to the desired element in the variable and enter a value. The array automatically expands to accommodate the new value. Empty elements fill with zeros if numeric, or empty arrays if a cell array. To decrease the size of an array, select the rows or columns that you want to remove by clicking in the row or column header, which selects the entire row, and then right-click, and select Delete from the context menu. Similarly, you can make changes to arrays in structure and objects.

To change the value of an element in the Variable Editor, click the element and type a new value. Press Enter, or click another element to make the change take effect. You can specify where the cursor moves to after you press Enter — see Preferences for the Variable Editor.

If you want to change the display format for the Variable Editor, select the View menu and choose a format. To change the default format for future use, use the Preferences dialog. For more information, see Preferences for the Variable Editor.

If you opened an existing MAT-file and made changes to it using the Variable Editor, save that MAT-file if you want the changes to be saved. For instructions, see Saving the Current Workspace.

Cut, Copy, Paste, and Clear Contents in the Variable Editor

You can cut or copy selected elements, rows, and columns in an array and paste them to another position in that or another open array. To select a column or row, click the row or column header (the element that shows the row or column number). Use Shift+click to choose contiguous elements, rows, or columns in the array, or Ctrl+A to select all elements. For the cut, copy, and paste operations, use the Edit menu, the context menu, or the toolbar buttons. You can undo the last operation you performed in the Variable Editor.

When you cut elements, the value of each element you cut becomes 0 if numeric or [] if a cell array. After cutting, select the elements whose value you want to replace with the cut elements and then choose Edit > Paste. If the shape of the elements you cut differs from the shape of the elements into which you are pasting, the Variable Editor pastes all the elements, either by expanding the selection to be pasted into, or by expanding the array size to allow all the elements to be pasted. Pasting copied elements is the same as pasting cut elements, but the elements copied maintain their value rather than becoming 0 or [].

To make the value of elements 0, select elements, rows, or columns and then select Edit > Clear Contents. This differs from a performing a Cut because the data from the selected elements does not move to the clipboard; any clipboard content is unaffected by Clear Contents.

Example Copying and Pasting Array Elements

In this example, two elements are copied. The selected area for pasting is only one element, but two elements are replaced.

Image of the Variable Editor showing copy area at elements 3,2 and 4,2.

Image of the Variable Editor showing paste area at element 3,1.

Image of the Variable Editor showing pasted values at 3,1 and 4,1.

Example Cutting and Pasting Array Elements

In this example, two rows are selected for cutting. One row is selected for pasting. The Variable Editor expands the array size, adding a row, so all cut elements can be pasted. The value of the cut elements cut becomes 0.

Image of the Variable Editor showing rows 2 and 3 selected for cutting.

Image of the Variable Editor showing row 4 selected for pasting, with 0s in the cut rows, 2 and 3.

Image of the Variable Editor showing row 5 added. Contents of rows 4 and 5 are from the cut rows, 2 and 3.

Insert and Delete in the Variable Editor

You can insert and delete elements, rows, and columns in arrays in the Variable Editor. When you select Edit > Insert, or Edit > Delete, a dialog box appears in which you specify rows, columns, or elements; for elements, the Variable Editor prompts you to provide, the direction for shifting existing elements.

Undo and Redo in the Variable Editor

You can undo the last action you performed in the Variable Editor, or redo a change after choosing undo. Select Edit > Undo or Edit > Redo. The actions supported are a change to a value you make by editing it in the Variable Editor, cutting, pasting, inserting, deleting, clearing contents, and pasting data from the Microsoft Excel application.

Exchanging Data with the Command Window

You can copy data from an array in the Variable Editor and paste it into the Command Window. You can also copy a value from the Command Window and paste it into an element in the Variable Editor. Be sure the data types are compatible. For example, you cannot paste text from the Command Window into a numeric array in the Variable Editor.

Exchanging Data with the Microsoft® Excel® Application

You can cut or copy cells from the Excel® application and paste them into the Variable Editor—use Edit > Paste from Excel. You can also cut or copy elements from an array in the Variable Editor and paste them into the Excel application.

Be sure the data types are compatible. For example, you cannot paste text from the Excel application into a numeric array in the Variable Editor.

Creating Graphs and Variables, and Data Brushing in the Variable Editor

You can create graphs from selected variables in the Variable Editor. To create a graph, select an element, row, or column in an array, and in the right-click context menu, choose the graph type. MATLAB presents allowable options for the selected data. In some cases, MATLAB makes assumptions, such as using cell2mat to convert selected cell array data, which cannot be plotted directly. For more information, see Plotting Process in the MATLAB Getting Started Guide.

To create a new variable, select an element, row, or column in an array in the Variable Editor, right-click, and from the context menu, select Create Variable from Selection.

Use the data brush feature, accessible via its toolbar button, to mark observations on graphs, allowing you to remove or save them to new variables. For more information, see Data Brushing with the Variable Editor in the Data Analysis documentation.

Preferences for the Variable Editor

To set preferences for the Variable Editor, select File > Preferences. The Preferences dialog box opens showing Variable Editor Preferences.

Format

Specify the default array output format of numeric values displayed in the Variable Editor. This affects only how numbers are displayed, not how MATLAB computes or saves them. For more information, see the reference page for format.

Editing

You can specify where the cursor moves to after you type an element and press Enter:

International Number Handling

You can specify how you want decimal numbers to be formatted when you cut or copy elements from the Variable Editor and paste them into text files or other applications. The Decimal separator to use when copying edit field is by default "." (period). If you are working in or providing data to a locale that uses a different character to delimit decimals, type that character in this preference and click OK or Apply.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS