MATLAB: How to work around the tunable parameter limitation in Simscape 3.0 (R2008b)

Simscapetunable

I read in the documentation of SimScape:
Simscape blocks do not support tunable parameters in either simulations or generated code.

Best Answer

There are no workarounds for the tunable parameter limitation in code generation. However to work around the tunable parameter limitation for simulation you can start consecutive simulations and start each simulation with the final state of the previous one.
For example if you would like to change the parameter at t=5 s and you have a simulation from 0s to 100s then then start a simulation from 0s to 5s, save the final state and use it in a second simulation from 5s to 100s as an initial state.
Attached you can find an example MATLAB file TuneSimscapeExample.m that uses the model tune_simscape.mdl file. To see the example enter the following in the MATLAB command line:
TuneSimscapeExample