Matlab tree diagram for variables

조회 수: 5 (최근 30일)
robin teslar
robin teslar 2019년 12월 15일
편집: Ram Vijayaragavan 2020년 1월 29일
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?

답변 (1개)

Ram Vijayaragavan
Ram Vijayaragavan 2020년 1월 29일
편집: Ram Vijayaragavan 2020년 1월 29일
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.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by