Each function has its own workspace, which is separate from the base workspace that is reserved for scripts and the command line. For the preferred ways to pass data between functions, see Share Data Between Workspaces.
The base workspace stores variables that you create at the command line or that a script creates when you run it from the command line or Editor. To protect the integrity of the data, every function has its own workspace that is separate from the base workspace and all other workspaces.
Use MATLAB® function and variable highlighting features to identify when and where your code uses a particular function or variable.
Create valid variable names and avoid potential naming conflicts.
Write code that MATLAB can optimize more effectively.