Programming and Data Types |
Local Variables
Each MATLAB function has its own local variables. These are separate from those of other functions, and from those of the base workspace. Variables defined in a function do not remain in memory from one function call to the next, unless they are defined as global
or persistent
.
Scripts, on the other hand, do not have a separate workspace. They store their variables in a workspace that is shared with the caller of the script. When called from the command line, they share the base workspace. When called from a function, they share that function's workspace.
Note If you run a script that alters a variable that already exists in the caller's workspace, that variable is overwritten by the script. |
Variables | Global Variables |