Skip to Main Content Skip to Search
Product Documentation

Viewing and Editing Workspace Variables with the Variable Editor

About the Variable Editor

The Variable Editor enables you to:

Edits you make in the Variable Editor immediately update the variable in the workspace.

Opening the Variable Editor

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

  1. If you do not have any, create some workspace variables, for example:

    A = magic(4);
    x = 0:.1:4*pi;
    y = sin(x);
    s = sprintf('This is yext\nwith two lines');
  2. If the Workspace browser is not open, select Desktop > Workspace.

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

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

  5. Click the Plot Selector to create a graph of the selected variables.

  6. Click a tabbed document to display a different variable that is open in the Variable Editor.

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

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

A

MATLAB returns:

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

Working with Different Data Types in the Variable Editor

Cell Arrays — Viewing and Editing in the Variable Editor

To view and edit the content of cell arrays in the Variable Editor, double-click a cell array element. It opens it a new Variable Editor document. You can then view and edit the contents of that element. The following illustrations show a 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

To view and edit the content of a structure currently displaying in the Variable Editor, following the procedure exemplified here:

  1. Create a structure by running the following code in the Command Window:

    S.name = 'Ed Plum'
    S.score = 83;
    S.grade = 'B+'
    S(2).name = 'Toni Miller';
    S(2).score = 91;
    S(2).grade = 'A-';
    S(3).name = 'Bill Cox';
    S(2).score = 92;
    S(3).grade = 'A-';
    S(3).score = 92;
    S(2).score = 91;
    
  2. Open S in the Variable Editor by double-clicking S in the Workspace Browser.

    The Variable Editor opens and displays S.

  3. Display S(1,2), by double-clicking the element in row 1, column 2.

    A new Variable Editor document opens and displays S(1,2).

  4. Edit the value for the grade field by right-clicking the value, and then select Edit Value from the context menu.

  5. Adjust the columns in the structure element document:

    • Sort columns by clicking a column header. Click the header again to reverse the sort order.

    • Show or hide columns by right-clicking any column header, and then, selecting or deselecting column header names, respectively. (This feature is available on Microsoft Windows platforms only.)

  6. Return to the structure document by clicking the Up button .

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 many MATLAB objects you create.

When you open an object in the Variable Editor, it displays Property, Value, Size, and other information. To:

The Variable Editor has special attributes for timeseries objects; for more information, see Viewing Time Series Objects.

The following illustration shows the sensorArray object of the sads class, in the Variable Editor. For more information about this example, see Example of Help for a Externally Supplied Class.

Image of Variable Editor showing the sensorArray object.

Lock icons, which can appear during debugging, denote protected and private properties of an object, indicating you do not have get access to those values outside class methods. The following illustration shows an object, resident. The Town property is protected and the State property is private. An attempt to get the State property programmatically returns the error, Getting the 'State' property of the 'Test' class is not allowed.

Editing Property Values in the Variable Editor.  To edit a property value while viewing the object, click the value field and then edit its contents. To more easily view a value before editing, double-click the value to display it in its own document, and then edit it.

When viewing a property, use the Up button to view the object. This button can help you navigate in the Variable Editor when there are many variables open.

If the Variable Editor window is small, the Up button might not be visible. To access it, click the >> button on the right side of the toolbar, and then select Go Up One Level from the menu.

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 displays in the Help browser. For user-created classes, help comments supplied in the class definition file display in HTML format in the Help browser. For more information, see Help for Classes You Create.

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 the 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) open in the Variable Editor.

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

You can view subsets of multidimensional arrays as long as the indexing expression evaluates to either a 1-D vector or a 2-D matrix. For example, R(2,:,:) , R(:,2,:), and R(:,:,2) display as follows.

You cannot edit subsets of multidimensional matrices. Because you can index into matrices in so many ways, the Variable Editor can incorrectly identify subscripts of variable elements that you might change. To avoid changing the wrong data elements, the Variable Editor prevents you from editing multidimensional matrices.

Navigating the Variable Editor Using Shortcut Keys

To move among elements in the Variable Editor, use the following shortcut keys (sometimes called hot keys). Navigating in the Variable Editor is much like navigating in the Microsoft Excel application. You cannot modify these keyboard shortcuts. For information on additional Variable Editor keyboard shortcuts (which you can modify), see Keyboard Shortcuts.

To:

Press this Key:

Commit changes to an element and move to next element.

Variable Editor Preferences enable you to specify what the next element is (the default is down).

Enter

Move right.

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

Tab

Move in opposite direction of Enter or Tab.

Shift+Enter or Shift+Tab

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

Page Up

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

Page Down

Move to column 1.

Home

Move to row 1, column 1.

Ctrl+Home

Move to last column in current row.

End

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

F2 (Ctrl+U on Apple Macintosh platforms)

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

To:Do This:

Increase the size of an array.

Scroll to the desired element in the variable and enter a value.

Empty elements fill with zeros if numeric, or empty arrays if a cell array.

Decrease the size of an array.

  1. Click in the row or column header of the rows or columns that you want to remove.

  2. Right-click, and then select Delete from the context menu.

Change the value of an element.

  1. Click the element, and then type a new value.

  2. Press Enter, or click another element.

Specify where the cursor moves to after you press Enter.

Select File > Preferences > Variable Editor, and then select Editing options:

  • To keep the cursor in the element where you typed, clear the Move selection after Enter check box.

  • To move the cursor to another element, select the Move selection after Enter check box. Then, in the Direction field, specify how you want the cursor to move.

Change the display format.

From the View menu, select a format.

Change the default format.

Select File > Preferences > Variable Editor, and then select a Format option.

Make MAT-file changes permanent.

See Saving the Current Workspace.

Selecting and Modifying Values in the Variable Editor

You can cut, copy, paste, insert, or delete selected elements, rows, and columns in an array, as described in the following table.

To:Do This:

Select a column or row.

Click the row or column header (the element that shows the row or column number).

Select contiguous elements, rows, or columns in an array.

Click the header of the first row, and then Shift+click additional rows.

Select all elements.

Select Edit > Select All.

Cut selected elements.

Select Edit > Cut or click the Cut button .

The value of each element you cut becomes 0 if numeric or [] if a cell array.

The cut values move to the clipboard.

Copy selected elements.

Select Edit > Copy or click the Copy button .

Paste cut or copied elements into selected elements.

Select Edit > Paste or click the Paste button .

If the shape of the elements you cut or copy differs from the shape of the elements into which you are pasting, the Variable Editor pastes all the elements. Either the Variable Editor expands the size of the selection you made, or it expands the array size to allow all the elements you are pasting.

Insert elements, rows, and columns in arrays.

  1. Click or select an area in the Variable Editor where you want to make an insertion.

  2. Select Edit > Insert.

  3. Complete the Insert dialog box to specify what you want to insert, and then click OK.

If you insert an entire row or column, the Insert dialog box does not open. MATLAB inserts a row above the select row or a column to the right of the selected column.

Delete elements, rows, and columns in arrays.

  1. Click or select the element or elements you want to delete.

  2. Select Edit > Delete.

  3. Complete the Delete dialog box to specify what you want to delete, and then click OK.

If you delete an entire row or column, the Delete dialog box does not open. MATLAB shifts columns or rows to replace the deleted column or row.

Undo the last operation.

Select Edit > Undo, or click the desktop toolbar Undo button.

Redo the last operation.

Select Edit > Redo, or click the desktop toolbar Redo button.

Set the value of elements to 0.

Select elements, rows, or columns for which you want to set the value to 0, and then select Edit > Clear Contents.

Example: Copying and Pasting Array Elements

In this example, you copy two elements. When you select one element for pasting, it replaces two elements.

  1. Create a matrix variable.

    A = magic(4);
  2. In the Workspace Browser, double-click A.

  3. In the Variable Editor, select and copy these two elements from rows 3 and 4:

    1. Click 7 (A(3,2)) and then Shift+click 14 (A(4,2)).

    2. Right-click the selection, and then select Copy from the context menu.

  4. Select 9 (A(3,1)), right-click, and then select Paste from the context menu.

    The column vector you copied ([7;14]) replaces the contents of rows 3 and 4 in column 1 (which had been [9,4]), even though you only selected the element containing 9. That is, the shape of the copied elements determines which values get replaced, starting at the upper left element.

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

Example: Cutting and Pasting Array Elements

In this example, you cut two rows and paste them into a single row. The Variable Editor expands the array size, adding a row to accommodate all pasted elements. The values of the elements you cut become 0.

  1. Create a matrix variable.

    A = magic(4);
  2. In the Workspace Browser, double-click A.

  3. In the Variable Editor, select rows 2 and 3:

    1. Click row number 2, and then Shift+click row number 3.

    2. Right-click the selection and select Cut from the context menu.

    The values in the cut rows all become 0 as a result of the cut operation.

  4. Select row number 4, and then right-click and select Paste from the context menu. The contents of the cut rows replace row 4 and extend the matrix to one additional row.

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

Exchanging Variable Editor Data with Other Tools and Applications

You can exchange Variable Editor data with other desktop tools and external applications if the data types are compatible. For example, you cannot paste text from the Command Window or an Microsoft Excel spreadsheet into a numeric array in the Variable Editor.

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

The Variable Editor, like the Workspace Browser, provides several methods for creating graphs without typing plotting commands. Once a graph displays, you can "brush" either the graph or array elements in the Variable Editor to see which observations correspond in the other.

Generating Graphs Automatically

You can create graphs from selected variables in the Variable Editor. To create a graph, select a data range, row, or column in an array, and choose a graph type in one of the ways described in the following bullets. MATLAB examines the selected data and determines which kinds of graphs can display it. In some cases, MATLAB performs data conversion, such as using cell2mat to transform cell array data—which cannot be plotted directly—to matrix data.

You can graph selections of numeric data and selected objects from the Variable Editor in three ways, illustrated here:

Assuming that you select the same graph type, all three methods generate identical plots of the selected data in the current or a new figure window.

The Plot Selector is the most flexible of the three methods. It lists more graph types that you can currently make and, in a separate tab, all graph types available to you. It also provides function help, and lets you prioritize graph types as a list of favorites. The following illustration compares it to the Graphics menu.

For more information about using the Plot Selector, see Creating Plots from the Workspace Browser.

Brushing Data in Linked Graphs

Data brushing is a technique for exploring where specific data observations fall in a set of graphs and tables. It helps you to visually identify relationships, outliers, trends, and noise that can be difficult to determine with numerical or statistical methods. Use the Data Brushing Tool on the Variable Editor and figure toolbars to mark specific observations (or ranges of them) in the Variable Editor and on graphs. You can remove brushed observations or save them to new variables.

If a variable you brush in the Variable Editor is plotted on a graph, selecting the Data Brushing tool and brushing array elements in the Variable Editor highlights those values in the graph displaying the variable you brush. Likewise, brushing observations on a linked plot highlights them in the Variable Editor. For data brush to communicate between the two windows, the figure must be in Linked Plot mode. Linked Plot mode connects a graph's XData, YData and ZData to its data sources in the current workspace. For more information, see Data Brushing with the Variable Editor and the reference pages for brush and linkdata.

  


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