Main Content

Workspace Variables and MAT Files

Manage data in the MATLAB® workspace

The workspace contains variables that you create or import into MATLAB from data files or other programs. You can view and edit the contents of the workspace in the Workspace panel or in the Command Window. For more information, see Create and Edit Variables.

Workspace variables do not persist after you exit MATLAB. To use your data across multiple sessions, save it to a compressed file with a .mat extension called a MAT file. You can restore saved data by loading a MAT file back into MATLAB. For more information, see Save and Load Workspace Variables.

Tools

Workspace PanelInteractively manage workspace contents
Variables EditorInteractively view, edit, and analyze workspace variables
Import ToolImport data from file

Live Editor Tasks

Import DataImport data from a file in the Live Editor (Since R2023a)

Functions

loadLoad variables from file into workspace
saveSave variables from workspace to file
matfileAccess and change variables in MAT-file without loading file into memory
dispDisplay value of variable
formattedDisplayTextCapture display output as string (Since R2021a)
whoList variables in workspace
whosList variables in workspace, with sizes and types
clearRemove items from workspace, freeing up system memory
clearvarsClear variables from memory

Topics

Troubleshooting

Unexpected Results When Loading Variables Within a Function

If you have a function that loads data from a MAT-file and find that MATLAB does not return the expected results, check whether any variables in the MAT-file share the same name as a MATLAB function.

Related Information