It appears that you are using MATLAB R2021a on Windows.
My understanding of your issue is that you've moved the model to a different directory, and you use a function that defines variables in the workspace, but you do not copy the function into the new directory containing the model.
You could try adding a call to your function in the InitFcn callback of your model:
- Right click on the Simulink canvas and click Model Properties (near the bottom)
- Click Callbacks
- Click InitFcn
- In the box on the right, add a call to your function. You can use run and fullfile to call a function which is not on the MATLAB path or in the current working directory. For example:
- Note that if your function is on the path, you do not need to use run and fullfile, you can just call it directly, like:
This will cause the files you call to run every time you simulate the model. If you do not want it to run every time you simulate the model, you could call the functions manually instead.