Overloading functions in Matlab and GNU Octave

Matlab and GNU Octave are constantly adding new functionality. However, legacy versions remain in use for years. Overloading a built-in function in Matlab and Octave requires logic to account for Octave providing many functions as m-files rather than builtin as in Matlab.

This example overloads isfile for single files.

Create a file “isfile.m” containing:

function ret = isfile(path)

if exist('isfile', 'builtin') == 5 || exist('isfile', 'file') == 2
  ret = builtin('isfile', path);
else
  ret = exist(path, 'file') == 2;
end

end