Matlab tree diagram for variables

1 visualizzazione (ultimi 30 giorni)
robin teslar
robin teslar il 15 Dic 2019
Hi
Coming from an Excel bg = new page means clean sheet, not so in Matlab
I am concerned about understanding the different levels/types of workspace
Is there such a thing as a tree diag to show the heirarchy of workspaces (3? base - workspace - function is this right?)
and then how variables are treated within these boundaries - you would think this was self evident but I dont feel that confident so far
Any advice or am I making an issue out of nothing?

Risposte (1)

Ram Vijayaragavan
Ram Vijayaragavan il 29 Gen 2020
Modificato: Ram Vijayaragavan il 29 Gen 2020
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.

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by