I think that is impossible, as you would have to have suitable S-function layers for the solver you intend to use (and I believe it is impossible to use these constructs for object oriented code like YALMIP, at least it used to be)
Adding to that, using MATLAB interpreted function is the easiest possible way to work with simulink. Going to S-functions will not make easier, only harder.
What is wrong with simply saving the data you need, and then doing a load in the function, or using global variables?