function outputs = mpsExecuteInMatlab (context, varargin)
    
    % Change directory if necessary
    restoreOldCwd = []; %#ok<NASGU>
    if ~isempty( context.workingDirectory )
        oldCwd = pwd;
        restoreOldCwd = onCleanup( @() cd( oldCwd ) );
        cd( context.workingDirectory );
    end
    
    % Change path if necessary
    restoreOldMatlabPath = []; %#ok<NASGU>
    if ~isempty( context.matlabPath )
        oldMatlabPath = path;
        restoreOldMatlabPath = onCleanup( @() path( oldMatlabPath ) );
        path( strjoin( context.matlabPath, pathsep ) );
    end
    
    % Set up the output cell array
    %
    outputs = cell( 1, context.numberOfOutputs );
    if  context.numberOfOutputs > 0
        % Execute and assign return value(s)
        %
        [outputs{:}] = feval( context.functionName, varargin{:} );
    else
        % Execute! no return value
        %
        feval( context.functionName, varargin{:} );
    end
end
