MATLAB: Is there a way for matlab to find a function in a file that doesn’t match the file name

path

I have a file that contains multiple functions. There is a function (functions name is GB5DOF) with the same name as the filename (GB5DOF.m), but I need to call other functions in that file that do not match the filename. GB5DOF is called without a problem. Is there a way to work around the requirement that a function have the same name as the filename to be called outside of the file? Thanks.

Best Answer

No. Local functions (those functions in a file after the first which normally(*) is named the same as the m-file containing it) are visible ONLY from within the scope of the m-file itself.
(*) NB: the actual name of the function itself inside the m-file is, in fact, irrelevant in the identification of the function. It is the file name itself that matters and only that filename.
>> type foo.m % display content of foo.m
function notfoo()
disp('In foo.m, function notfoo()')
Evaluate foo...
>> foo
In foo.m, function notfoo()
Executed foo.m which contains 'notfoo' as the function name internally.
>> which foo
C:\ML_R2014b\work\foo.m
>> notfoo % try to execute notfoo...
Undefined function or variable 'notfoo'.
>>
There is no such function known as what is internal to the file is immaterial to the parser until it's been loaded at which time the name doesn't matter.
ADDENDUM
What you could do (altho I don't recommend it) would be make a top-level function in the file that is used in turn to call the others. It would undoubtedly be better to "when in Rome do as..." in using the Matlab paradigm of structuring code as it expects despite that being different than most compiled languages.
Perhaps this could be the place for a more general OOP approach wherein these different functions become methods...