Simulink Functionを使ってみてはどうでしょうか。
添付ファイルに、簡単にモデルを用意しました。バージョンはR2020bです。sim()で呼び出しているSimulinkの処理を、Simulink Functionブロック内に移せば、実行できると思います。
注意点ですが、Simulink Function内にはサンプリング時間に依存した処理やブロックを入れないようにしてください。
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!