0
0
MATLABdata~5 mins

Workspace and variable management in MATLAB

Choose your learning style9 modes available
Introduction

The workspace in MATLAB is where your variables live while you work. Managing variables helps keep your work organized and your computer memory free.

When you want to see what variables you have created so far.
When you need to clear variables to free up memory.
When you want to save your variables to use later.
When you want to load saved variables back into your workspace.
When you want to rename or change variables to avoid confusion.
Syntax
MATLAB
clear variableName
clear % clears all variables
who
whos
save filename
load filename

clear variableName removes a specific variable from the workspace.

who lists variable names; whos shows details like size and type.

Examples
This shows the names of variables currently in the workspace.
MATLAB
x = 10;
y = 20;
who
This removes variable x and then lists remaining variables.
MATLAB
clear x
who
This saves all variables to a file, clears workspace, then loads them back and shows details.
MATLAB
save myData
clear
load myData
whos
Sample Program

This program creates two variables, shows details, clears one, lists remaining, saves all, clears workspace, loads saved variables, and lists them again.

MATLAB
a = 5;
b = 15;
whos
clear a
who
save myVars
clear
load myVars
who
OutputSuccess
Important Notes

Use clear carefully; it deletes variables and you cannot undo it.

Saving variables helps you keep your work safe and share it with others.

Summary

The workspace holds your variables while you work in MATLAB.

Use who and whos to see what variables you have.

Use clear, save, and load to manage your variables and workspace.