Setting different cost W for each stage in a horizon in Simulink

Hi :wave:

I am using the MATLAB interface to design a MPC for a trajectory tracking problem. The cost function I am using is least square type. I tried to set different value for the weight matrix at each stage in a horizon and already made it in MATLAB script by using the method ocp.set(). Now I generated the code from MATLAB script and tried to do the same thing in S-function in my Simulink model. I took a look at the example “simulink_example_advanced.m” and learned how to set the cost as an input for S-function. However, the approach shown in this example sets the same weight value for all the stages in a horizon. So my question is, whether there is a way to set different value for the weight in different stage in a horizon, just like what can be achieved in MATLAB, Python or C interfaces? If possible, how can I achieve this?

Thanks in advance!


this is not possible in the Simulink interface for now.

You would have to modify the interface.
Either in Simulink:

Or more general in the solver: