
- Matlab Tutorial
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
- MATLAB - Useful Resources
- MATLAB - Quick Guide
- MATLAB - Useful Resources
- MATLAB - Discussion
MATLAB - Workspace
In matlab workspace, also called workspace browser, is a place where you will find all the variables along with its most recent values stored in memory. All the variables available in workspace are the ones which you have used while writing your code or have imported data from other programs or files.The workspace acts as a temporary storage and allows you to create, read,update or delete the variables.
The workspace reference for the stored variables are available only if this matlab is open, once close the workspace is erased.But incase if you want to use it in future you can always save it with .mat extension.
Let us understand the workspace in more detail in this section.
- Opening of workspace browser in matlab
- Creating and editing variables in workspace
- Save and Load Workspace Variables
- Clearing Workspace
Opening of Workspace Browser in Matlab
Open matlab, most of the time workspace is by default selected as part of the layout, in case you don't see it. Here are a few ways to open a workspace for you.
Go to Home tab, inside the Environment section click on layout as shown below −

Open layout and it should show the following details

Incase workspace is not selected for you , select it and you should see workspace as part of the layout as shown below.

You can make use of the command: workspace in the matlab command window and once it executes it will open the workspace.
>>workspace
Creating and Editing Variables in Workspace
Let us create a few variables in the command window and see the same being stored in the workspace.
Below we have created a matrix A in command window
>> A = [1 2 3; 4 5 6; 7 8 9] A = 1 2 3 4 5 6 7 8 9 >>
Once it is executed you will see variable A in workspace.

The workspace stored the Name, value, size and class of the variable A created.
To edit the value of the variable A in workspace, simply right click and select Edit Value as shown below.

On you click on Edit Value you will see you can edit the value as shown below −

Save and Load Workspace Variables
The workspace is cleared when you exit from matlab. But you can save the workspace in case you want to use it in future.
The file is saved with the .mat extension. When you want it next, open the file in your matlab session.
Here are a few ways to save the workspace variables.
Go to Home tab and you should see the VARIABLE section as shown below

Click on Save Workspace. It will open the file save dialog window as shown below

Save the file with the .mat extension
You can also select a subset of variables in the workspace , right click and click on save selection as shown below −

Another way to save the full workspace is to right-click on the workspace and click on save workspace as shown below.

Since we are done with saving workspace, in this section we will learn how to load the workspace or use the variables present in the workspace.
Here are a few ways to get the variables or load the workspace in matlab.
Inside the Home tab, click on open and select the workspace file you have saved.Click on it and the same will load inside the workspace.
Using load method()
The load() method takes in the filename and you can also specify the variables that you need in it.
Example
load(a)
Here a is the file name a.mat. You dont have to mention the .mat in the method.
When you execute the same in the command window in matlab you will get below output.
You can also specify the variable names you want to load from the a.mat . For example
Consider the file a.mat has variables A, B and C.
If you want to load only A and C you can specify in load method as shown below
load('a', 'A', C)
Using Whos Command
The file content saved can be viewed as shown below.
whos -file a.mat
When you execute in matlab command window the output is as follows −
>> whos -file a.mat Name Size Bytes Class Attributes A 1x5 40 double B 1x4 32 double C 1x2 16 double >>
The Bytes tells about the memory used by each variable. Matlab takes care of compressing the data so that less memory is used.
Using Who Command
Similar to whos there is another command who, that displays the names of the variables in workspace.
Example
>> who Your variables are: A B C K >>
Using disp() Method
You can also make use of disp() method, it also takes care of displaying the variables values.
disp(A)
The output on execution is −
>> disp(A) 0.8147 0.9058 0.1270 0.9134 0.6324 >>
Using openvar() Method
This method takes in a variable as the input and the variable is opened inside the variable editor. Later you can change the values or delete them as per your requirement.
openvar(A)
On execution in matlab command window the output is −

Clearing Workspace
With clear workspace it will remove all the variables present in the workspace.By default when the matlab session is closed the workspace is cleared.
But if you still want to clear the workspace when the session is active, here are a few ways to do it.
Inside Home tab, you can make use of clear workspace as shown below.

You can also make use of the command clear inside the matlab command window to clear and remove all items from workspace.
clear // removes all the variables present in the workspace clear A // will only remove the variable A from the workspace clear -regexp ^test ^a; // makes use of regular expression and removes all the variables that start with test and a.
Using clearvars Command
This method will remove all the variables present in the workspace. If you specify the variable names only those are removed.
Example
clearvars clearvars A B C