Variable Step Speed Cruise Control System
This example shows how to simulate and generate code for the Controller subsystem from a speed cruise control model by using variable continuous step solver.
Open the Model
open_system('plcdemo_cruise_control_continuous');

To start the simulation, click Run.
Generate Code
To generate code for the Controller subsystem, use plcgeneratecode:
generatedfiles =
plcgeneratecode('plcdemo_cruise_control_continuous/Controller');
In this model, the model solver is set to variable-step continuous (ode45); the sample time of the controller subsystem is set to 0.05. To set the controller sample time, right click on the controller block and then click the Block Parameters button. Set the Sample time parameter to 0.05. This method allows combined modeling of discrete-time controller and continuous-time plant in the same model with PLC code generation support.