You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: set.m
    path of file: ./repos/d2d/arFramework3/ThirdParty/StrucID/adimat/opt_sp_derivclass/@adderivsp
    
    the code of the file until where you have to start completion: function g=set(g, arg, varargin)
%ADDERIV/SET -- Set the derivative or global option.
%
%   g= set(g, {i}, A); Sets the i-th entry of g to A and returns 
%       the modified g. Make sure, that size(A)== size(g{1}).
%
%   g= set(g, {range,range}, A, B, ...); Sets the entries specified by the 
%       ranges of g to the values of A, B, ... . The number of objects 
%       specified by the range has to equal to the number of inputs A,B,...
%
%   g= set(g, 'optionname', newval); Sets the global option to the newval.
%       Beware this heavily influences the behaviour of the ADiMat runtime
%       class. Be sure to know what you are doing. This method is for

    
function g=set(g, arg, varargin)
%ADDERIV/SET -- Set the derivative or global option.
%
%   g= set(g, {i}, A); Sets the i-th entry of g to A and returns 
%       the modified g. Make sure, that size(A)== size(g{1}).
%
%   g= set(g, {range,range}, A, B, ...); Sets the entries specified by the 
%       ranges of g to the values of A, B, ... . The number of objects 
%       specified by the range has to equal to the number of inputs A,B,...
%
%   g= set(g, 'optionname', newval); Sets the global option to the newval.
%       Beware this heavily influences the behaviour of the ADiMat runtime
%       class. Be sure to know what you are doing. This method is for
%       experts use only!
%       Available options for setting are:
%
%     'direct':
%       Set the values of g in one sweep. Have a look at get(g,'direct')
%       to find out how newvalue has to look like. g needs to be preallocated
%       and size(newval)==size(g{1}).* get(g, 'NumberOfDirectionalDerivatives')
%
%     'NumberOfDirectionalDerivatives':
%       Set the number of directional derivatives to newval. This 
%       option sets the number of directional derivatives, that is used
%       for creating zero derivative objects using g_zeros and h_zeros.
%       Setting a new value is possible only after clearing all options
%       or during the first use of the ADiMat runtime system. Be sure to
%       know what you are doing!
%
%   Hint: set(g, ':', value) is not valid!
%
%   All set-operations may be applied to single and two-dimensional 
%   derivative objects.
%
% Copyright 2001-2005 Andre Vehreschild, Institute for Scientific Computing   
%                     RWTH Aachen University
% This code is under development! Use at your own risk! Duplication,
% modification and distribution FORBIDDEN!

if isa(arg, 'double') && size(arg)== [1 1]
   arg= {arg};
end