Additional Information

Global variables have their own workspace, which is separate from the base and function workspaces.

Using global variables is inefficient. MATLAB applies memory optimization to input variables in functions, but not to global variables. For more information see Avoid Unnecessary Copies of Data.

Also, global variables carry notable risks. Any function can access and update a global variable. Other functions that use the variable might return unexpected results. For example:

Use global variables sparingly, if at all.

For more information on variables and the workspace, see Global Variables subsection on Share Data Between Workspaces page.