MATLAB: Re-utilizing a piece of code within several functions

matlab functionscript

Dear All!
I have a big initialization section which I wish to use within several matlab functions. If I run this section as a script whithin a function, it does not work. If a write this part as a function, it makes a mess as it returns dozens of variables.
Is there a way to include this part into a function without passing parameters? Something like
include('init.m')
or so. Thanks Dmitry

Best Answer

run('init.m')
exists but expects a script, and is the same thing as
init
(except that run() can be given a path to a .m and will change directories to be able to execute it.)
If running the script "does not work" then run() will not work either.