Base Workspace:
The base workspace stores variables that you create at the command line.
How to create Base Workspace Variables?
- By defining the variables at the command line.
- Any variables that scripts create, assuming that you run the script from the command line or from the Editor.
What is the scope of the Base Workspace Variables?
Variables in the base workspace exist until you clear them or end your MATLAB® session.
Function Workspace:
Every function has its own function workspace. Even local functions in a common file have their own workspaces. Variables specific to a function workspace are called local variables.
Functions do not use the base workspace. Each function workspace is separate from the base workspace and all other workspaces to protect the integrity of the data
How to create Function Workspace Variables?
When you call a script from a function, the script uses the function workspace.
What is the scope of the Function Workspace Variables?
Typically, local variables do not remain in memory from one function call to the next. So the scope is within the function where the variable is declared.
How does the concept of function workspace applies to the nested functions?
Like local functions, nested functions have their own workspaces. However, these workspaces are unique in two significant ways:
- Nested functions can access and modify variables in the workspaces of the functions that contain them.
- All of the variables in nested functions or the functions that contain them must be explicitly defined. That is, you cannot call a function or script that assigns values to variables unless those variables already exist in the function workspace.