The common way to do this sort of thing is to have a script called everything.m
% everything.m
foo();
and one file for each function you want to be able to use:
% foo.m
function foo()
...
end
Executing everything.m
then calls all the functions you want to call (plus any additional tasks you might want to do at that stage).
Having all your functions on the Matlab path, means they are "defined" (accessible from the Matlab command prompt or inside other functions). This is "the Matlab way" :)
Note that it is possible to have more than one function per file,
% bar.m
function bar()
otherFunction(); % WORKS OK
end
function otherFunction()
...
end
only the topmost function will be visible in the Matlab command prompt:
>> bar
>> % no error
>>
>> otherFunction
??? Undefined function or variable 'otherFunction'.