Try adding the source files that are used for S-function Through
Configuration Parameters -->Code Generation-->Custom Code -->Include list of additional-->Source files.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!