This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

View, Edit, and Copy Variables

View and Edit Variables

Display Variables and Values

This table shows how to view workspace variables and their values.

List current workspace variables

Use the who function.

To list information about size and class, use the whos function.

Display variable contents in the Command Window

Type the variable name at the command prompt.

Open a variable in the Variables editor

Do one of the following:

  • Use the openvar function. For example, to open the variable A, type

  • In the Workspace browser, double-click a variable name.

    Some variables open a viewer or other tool appropriate for the variable, such as timeseries. For details, see the documentation for that data or object type.

    Note:   The maximum number of elements in a variable that you can open in the Variables editor depends on your operating system and the amount of physical memory installed on your system

View and Edit Variables Interactively

This example shows how to open a variable and to navigate and edit its contents graphically. You cannot edit elements or subsets of multidimensional arrays in the Variables editor.

  1. Create a cell array, C.

    A = magic(4);
    C = {A A A};

  2. In the Workspace browser, open variable C to view its contents, by doing one of the following:

    • Use the openvar function.


    • In the Workspace browser, double-click the variable name C.

    The variable C opens in the Variables editor.

    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.

  3. Double-click element C{1,1} to view the contents of that cell. The element opens in a new document within the Variables editor.

  4. Edit the value of an array element by clicking the element and typing a new value. Press Enter, or click another element.

    Increase the size of the array in C{1,1} by entering a value in element (5,5).

    Empty elements are assigned default values. Default assignments are

    • 0 for numeric arrays

    • [] for cell arrays and structure arrays

    • <undefined> for categorical variables

  5. Remove a row by clicking in its row header. Right-click, and then select Delete Row.

  6. Cut the elements of the first column by selecting column header. Right-click, and then select Cut. The value of each element you cut becomes 0 if numeric, or [ ] if a cell array. The cut values move to the clipboard.

  7. Paste the cut elements into another column by selecting the element where you want the insertion to begin. Right-click, and then select Paste.

  8. Change how numbers display when editing variables. In the Format section of the View tab, select a number display format.

  9. On the View tab, use the Go Up button to return to the cell array or structure.

Changes you make in the Variables editor are automatically saved in the workspace.

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

Edit Table and Structure Array Data Interactively

This example shows how to edit table data in the Variables editor. Editing structure array data is similar.

Create a sample table and open it in the Variables editor.

load patients.mat; 
T = table(LastName,Age,Height,Weight); 

Modify a column name or row name of the table by double-clicking the name and typing new text. In this example, double-click the variable name, Weight, to rename it. For structure arrays, you can modify a field name in this manner.

    Note:   The contents of a table are only visible and modifiable when the number of variables is fewer than 5000. When the number of variables equals or exceeds 5000, you can only view the table properties.

By default, changes made in the Variables editor appear at the command line. You can suppress code display at the command line. On the View tab, clear the Show MATLAB Code check box.

Reorder the variables in the table by hovering over the left side of a variable until a four-headed arrow appears. Then, click and drag the column to a new location. You can reorder the fields in a structure array in the same manner.

Modify the units and description properties of the table variable, Height, by clicking the arrow that appears to the right of the variable name. Then, enter the new text in the Units and Description fields.

Copy, Paste, and Rename Workspace Variables


Copy variable names to clipboard

In the Workspace browser, select the variables, right-click, and then select Copy. Then, you can paste the names, for example, into the Command Window or an external application. Multiple variables are comma-separated.

Paste cells from Microsoft® Excel® spreadsheet

In a variable open in the Variables editor, right-click, and then select Paste Excel Data.

Create a new workspace variable from an existing variable.

For a variable open in the Variables editor, select an element, data range, row, or column in an array, and then select New Variable from Selection.

Rename a workspace variable

In the Workspace browser, do either of the following:

  • Right-click the variable name, and then select Rename.

  • Type the new variable name over the existing name, and then press Enter.

    Tip   If you cut and paste values from the Variables editor into text files or other applications, you can change the character that delimits decimals in the data that is exported. You might do this, for instance, if you provide data to a locale that uses a character other than the period (.). To change the delimiter character, specify a Decimal separator for exporting numeric data via system clipboard in the Variables Preferences.

Was this topic helpful?