Main Content

prepareToDeploy

Class: sdo.SimulationTest
Package: sdo

Configure simulation scenario for deployment with Simulink Compiler

Description

Simulator_out = prepareToDeploy(Simulator) configures the Simulink® model and simulation scenario specified as the sdo.SimulationTest object Simulator, for deployment with Simulink Compiler™.

prepareToDeploy saves logging and parameter information in the simulation scenario Simulator_out so that the sdo.SimulationTest object does not need to perform model error checking or configuration when deployed as part of an executable.

example

Simulator_out = prepareToDeploy(Simulator,p) configures the sdo.SimulationTest object Simulator for deployment with an optional vector p of param.Continuous objects that can be used to modify the model variables once the model is deployed.

Input Arguments

expand all

Simulation scenario for a Simulink model, specified as an sdo.SimulationTest object. A simulation scenario specifies input signals, model parameter and initial state values, and signals to log for a model.

Parameters to modify the deployed model, specified as a vector of param.Continuous objects. You can use p to modify the model variables once the model is deployed.

Output Arguments

expand all

Simulation scenario configured for deployment with Simulink Compiler, returned as an sdo.SimulationTest object.

Examples

expand all

For this example, set up your parameter estimation problem using the Parameter Estimator app and generate MATLAB code from it. For more information on generating MATLAB code from the app, see Generate MATLAB Code for Parameter Estimation Problems (GUI). Alternatively, you can also set up your estimation problem at the command line.

Next, split the generated MATLAB code just before the estimation objective function is defined. This results in two files - a run function and a setup function, as described in Deployed Application of Parameter Estimation.

In the setup function, add the following lines of code at the end to configure the experiment and simulation test objects for deployment and save them to a MAT-file.

Experiment_out = prepareToDeploy(Experiement);
Simulator = createSimulator(Experiment_out);
Simulator = prepareToDeploy(Simulator,p);
save ObjectsToDeploy Experiment_out Simulator p

In the run function, add the following lines of code at the beginning of the function to include the Simulink model in the compiled code and load the objects that were saved in the setup function.

%#function simulink_model_name.slx
load ObjectsToDeploy Experiment_out Simulator p

Next, add the following lines to load the experiment data and update the experiment object. For this example, assume that the experiment data is contained in the first three columns of a Microsoft Excel spreadsheet file named fname.xls.

d = xlsread(fname);
u = timeseries(d(:,3),d(:,1));
y = timeseries(d(:,2),d(:,1));
Experiment_out = updateIOData(Experiment_out,'simulink_model_name/param1',u);
Experiment_out = updateIOData(Experiment_out,'simulink_model_name/param2',y);

For a detailed example showing how to deploy your parameter estimation problem using the Simulink Compiler, see Deployed Application of Parameter Estimation.

Introduced in R2020a