Workspace Variables and MAT Files
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 Panel | Interactively manage workspace contents |
Variables Editor | Interactively view, edit, and analyze workspace variables |
Import Tool | Import data from file |
Live Editor Tasks
Import Data | Import data from a file in the Live Editor (Since R2023a) |
Functions
load | Load variables from file into workspace |
save | Save variables from workspace to file |
matfile | Access and change variables in MAT-file without loading file into memory |
disp | Display value of variable |
formattedDisplayText | Capture display output as string (Since R2021a) |
who | List variables in workspace |
whos | List variables in workspace, with sizes and types |
clear | Remove items from workspace, freeing up system memory |
clearvars | Clear variables from memory |
Topics
- Create and Edit Variables
Create, edit, and copy variables in the MATLAB workspace using the Command Window, Workspace panel, and Variables editor.
- Save and Load Workspace Variables
Save some or all variables in the current workspace and reload the variables later during the current MATLAB session, or during another session.
- Modify Workspace and Variables Settings
Set settings for the Workspace panel and Variables editor.
- MAT-File Versions
There are several versions of MAT-files that each support an increasing set of features, starting with MAT-file Version 4.
- Compare and Merge MAT-files
View and merge changes between two MAT-files.
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.