function [out1, varargout] = scope(arg1, varargin) % This is a global variable; any functions that declar a global variable % with the same name share it in memory. If any other workspace uses arg2, % after this function their value of arg2 will be changed. After running this % program you can type 'global arg2' in the command window to view its value global arg2 arg2 = 21; % Since the name of this variable is not listed in the output arguments, it % will be trashed once the function finishes. It only lives in this scope, % and can be accessed neither by the command window nor sub_function temp_variable = 23; % run feval with this returned variable to use the function out of its % original scope out1 = @sub_function; % Varargout must be a cell array varargout = { varargin{end:-1:1}; }; function o = sub_function % This function can only be accessed by other functions within the file % scope.m unless its function handle is passed out of the file o = 'MATLAB scope is a little confusing';