I would like to have some file, myfunc.m, in my MATLAB path and somehow load its contents into a MATLAB function block automatically just before the simulation
myfunc.m
I am thinking that model callbacks may be a way to do what you want, though I have not used this technique myself.