lettura simple

Matlab Workspace

In this guide, I'll talk to you about the Matlab workspace. Let's dive in.

So, what is the workspace? The workspace is the place where all the variables, values, and commands you've used during your current Matlab session are stored in memory.

Now, let's take a concrete example.

Suppose you type "3+5" in the command window and hit enter.

>> 3+5

Matlab will process the command, store the result in a variable called "ans" and display the contents of that variable below the command.

ans = 8

Whenever you perform an operation on the Matlab command prompt, it automatically registers the result in a global variable called "ans."

What's a global variable? A global variable can be accessed from anywhere in the workspace, which is different from local variables that are only visible within a function or method.

So, where can you find this workspace?

It's located in the panel on the left side of Matlab.

Workspace window in Matlab

If you can't see it, click on "Layout" in the top menu, then select "Show" in the Layout Options section, and check the box next to "Workspace."

Matlab layout

In the workspace window, you'll find all the variables you've used during your work session.

For example, suppose you type "prova=5" and hit enter.

This command assigns the value of 5 to a session variable called "prova".

>> prova = 5

Note. In this example, I've named the variable 'prova'. You can use any other variable name you want.

Now you can also see the 'prova' variable in the workspace.

Defining the prova variable

How to clear the workspace?

Now, here's the interesting part. To clear the workspace, all you need to do is type "clear" in the command window.


This command removes the variable names and values assigned from the workspace, effectively resetting the working memory and allowing you to start a new session in Matlab.

Resetting the Matlab workspace with the 'clear' command

This way, you can reset the working memory and start a new session in Matlab.

That's it. The Matlab Workspace in a nutshell.

Report a mistake or post a question