| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
The Variable Editor is a desktop component that lets you display variables in the current workspace. Use it to view and edit values of one or two-dimensional arrays, character strings, cell arrays, structures, and objects and their properties. You can also view the contents of multidimensional arrays. Edits you make in the Variable Editor immediately update the variable in the workspace. It also supports copying and pasting of data values.
To open the Variable Editor from the Workspace browser, perform these steps:
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');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.
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.

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.
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')
You need to enclose the name of the variable name in single quotes, because the Variable Editor requires strings, not variable references. It needs the name of the variable so MATLAB can notify it when the variable changes value, disappears, or goes out of scope. If you were to type openvar(A) instead of openvar('A'), the Variable Editor would receive the value of A instead of its name. However, openvar varname and openvar 'varname' both work, as the function assumes string arguments when using command syntax. See Command vs. Function Syntax in the MATLAB Programming Fundamentals documentation for more information.
MATLAB opens A in the Variable Editor.
To see the contents of a variable in the workspace, 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 1You 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 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.


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.


The information shown for the element of the structure is like
what the Workspace browser displays: Field, Value, Size and
other information. 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. 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. The button helps you navigate
in the Variable Editor when there are many variables open.
To edit an element, you can click the value and change its value. Or double click the element; a new Variable Editor document containing it opens. Click the value and then change it. 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).

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 show or hide a column, right-click the column header. To sort by a column, click that column header; to reverse the sort order, click the column header again. You can view help for the class by clicking the class name link. The Variable Editor has special attributes for timeseries objects; for more information, see Viewing Time Series Objects in the MATLAB Data Analysis documentation.
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 User-Created Class.

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 value while viewing the object, click the value field and edit its contents, as shown in the following illustration.

Alternatively, double-click the value, which displays the value
in its own document where you can more easily view and edit it. In
the following illustration, the sensorArray.Spacing property
opens in its own document when you double-click it. When viewing a
property, use the Up button
to view the object, for
this example, sensorArray. 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 get to it, click the >> More Menu button on the right side of the toolbar and choose 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 Providing Help for Classes You Create.
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.

You can view subsets of multidimensional arrays as long as the indexing expression evaluate 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.
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. Preferences for the Variable Editor let you specify what the next element is (the 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 |
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. Clicking a header selects the entire row or column. Then right-click, and select Delete from the context menu. Similarly, you can update 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 effect the change. 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 open an existing MAT-file and change it using the Variable Editor, save that MAT-file if you want the changes to be permanent. For instructions, see Saving the Current Workspace.
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 it expands the size of the selection you made, or it expands the array size to allow all the elements you are pasting. 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. Clearing differs from cutting because the data from the selected elements does not move to the clipboard or modify it.
In this example, you copy two elements. When you select one element for pasting, it replaces two elements.
Create a matrix variable.
A = magic(4);
Select rows 3 and 4 or column 2 by clicking 7 (A(3,2)) and then Shift+clicking 14 (A(4,2)). Right-click the selection and select Copy from the context menu. You can also press Ctrl+C or chose Copy from the Edit menu to copy the values.

Select 9 (A(3,1)) and select Paste from the context menu or Edit menu, or type Ctrl+V.

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.

select two rows and cut their contents. Select one row for pasting. The Variable Editor expands the array size, adding a row to accommodate all cut elements. The values of the elements you cut becomes 0.
Create a matrix variable.
A = magic(4);
Select rows 2 by clicking its row number, then Shift+click the row number for row 3 to select both rows. Right-click the selection and select Cut from the context menu. You can also press Ctrl+X or chose Cut from the Edit menu to cut the values and copy them to the clipboard.

The values in the cut rows all become 0 as a result of the cut operation.
Select row 4 entirely and select Paste from the context menu or Edit menu, or type Ctrl+V.

The contents of the cut rows replace row 4 and extend the matrix to have an additional row.

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. When you delete elements, the Variable Editor prompts you to provide, the direction for shifting existing elements.
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 the following:
A change to a value you make by editing it in the Variable Editor
Cutting
Pasting
Inserting
Deleting
Clearing contents
Pasting data from the Microsoft Excel application.
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 that the data types are compatible. For example, you cannot paste text from the Command Window into a numeric array in the Variable Editor.
You can also create new variables from a selected element, data range, row, or column in an array in the Variable Editor. Right-click, and from the context menu, select Create Variable from Selection, or do the same from the Edit menu.
You can cut or copy cells from the Microsoft 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 that the data types are compatible. For example, you cannot paste text from the Excel application into a numeric array 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.
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. For more information, see Plotting Process in the MATLAB Getting Started Guide.
You can graph selections of numeric data and selected objects from the Variable Editor in three ways, illustrated here:
Select data and choose from a list of graph types from the Graphics menu.

Select data, right-click, and choose from a list of graph types from the context menu.

The types of graphs available on the context menu and the Graphics menu are the same.
Select data and click the Plot Selector toolbar icon to generate the type of plot it displays.

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 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.
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 in
the MATLAB Data Analysis documentation and the reference pages
for brush and linkdata.
To set preferences for the Variable Editor, select File > Preferences > Variable Editor. The Preferences dialog box opens showing Variable Editor Preferences.
Specify the default array output format of numeric values displayed in the Variable Editor. This format preference affects only how numbers display, not how MATLAB computes or saves them. For more information, see the reference page for format.
You can specify where the cursor moves to after you type an element and press Enter:
If you want the cursor to remain at the element where you typed, clear the Move selection after Enter check box.
If you want the cursor to move to another element, select the Move selection after Enter check box. Choose the Direction to specify how you want the cursor to move. For example, if you want the cursor to move right one element after you press Enter, select Right.
You can specify the decimal format of numbers you cut or copy from the Variable Editor when you paste them into text files or other applications. The Decimal separator for exporting numeric data via system clipboard 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. This preference has no effect on numeric data copied from and pasted into MATLAB documents or into the Command Window. Within MATLAB, decimal separators are always periods.
![]() | MATLAB Workspace | Managing Files in MATLAB | ![]() |

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 |