MATLAB: How to initialize start values for variables and then overwrite in simulink

initializationsimulinkstart values

I want to set start values for a list of 37 input variables (Xo(1) to Xo(37)). These should be used for a matlab function that calculates new values for the 37 variables. For the next time step the new calculated values should be used as input data. So the start values have to be overwritten or the model has to know that it should use the setted input data only for the first step. How can I do this in simulink?

Best Answer

You can initialize values in Simulink by using File->Model Properties->Model Properties->Callbacks->PreLoadFcn or InitFcn. The difference between them is PreLoadFcn runs the code within when the model is being opened at the very beginning. InitFcn runs the code within when you hit the Play button but my suggestion is to use PreLoadFcn
You can overwrite those values in run time only and only by using Masks. If you do not know about them, I suggest you to read about them but basically what you do is to gather the blocks within a subsystem and create a mask for it. Then, you create edit fields which refers to a single parameter in your model within the subsystem and you can change it in run time by simply writing its value in there and clicking Apply.