Deploy Simulations with Tunable Parameters
With Simulink® Compiler™, you can deploy simulations that use tunable parameters.
As you construct a model, you can experiment with block parameters, such as the coefficients of a Transfer Fcn block, to help you decide which blocks to use. You can simulate the model with different parameter values, and capture and observe the simulation output.
You can change the values of most numeric block parameters during a simulation. This technique allows you to quickly test parameter values while you develop an algorithm. You can:
Tune and optimize control parameters.
Calibrate model parameters.
Test control robustness under different conditions.
The following example shows how to set a tunable parameter in a model, write a standalone application that can be used to tune the parameters, and analyze the simulations. For more information on tunable parameters, see Tune and Experiment with Block Parameter Values.
Prepare a Script to Deploy Simulations with Parameter Tuning
In this example, create a MATLAB® function to simulate the model
sldemo_suspn_3dof with the
Simulink.SimulationInput. Save the script as
deployParameterTuning.m on the MATLAB path.
Prepare a Function to Deploy
Create a function called
deployParameterTuning containing the code
shown below. This code creates a
Simulink.SimulationInput object for
mb is the value that we
pass through the
setVariable method for the tunable parameter,
Mb. To configure this script to be deployed, use the function
simulink.compiler.configureForDeployment configures the
Simulink.SimulationInput object for by deployment by setting its
simulation mode to Rapid Accelerator and by restricting inputs that require rebuilding the
function deployParameterTuning(oName, mb) if ischar(mb) || isstring(mb) mb = str2double(mb); end if isnan(mb) || ~isa(mb, 'double') || ~isscalar(mb) disp('The value of mb given to deployParameterTuning must be a double scalar or a string or character that can be converted to a double scalar'); end in = Simulink.SimulationInput('sldemo_suspn_3dof'); in = in.setVariable('Mb', mb); in = simulink.compiler.configureForDeployment(in); out = sim(in); save(oName, 'out'); end
Deploy the Prepared Function
On the Apps tab, in the Apps section, click the arrow. In Application Deployment, click Application Compiler.
Alternately, you can open the Application Compiler app by entering
applicationCompilerat the MATLAB prompt.
In the Compiler project window, specify the main file of the MATLAB application that you want to deploy.
In the Main File section, click .
In the Add Files window, browse to path where you have saved the prepared function, and select
deployParameterTuning.m. Click Open.
deployParameterTuning.mis added to the list of main files.
Decide whether to include the MATLAB Runtime installer in the generated application by selecting one of the two options in the Packaging Options section:
Runtime downloaded from web — Generates an installer that downloads the MATLAB Runtime and installs it along with the deployed MATLAB application.
Runtime included in package — Generates an installer that includes the MATLAB Runtime installer.
Customize the packaged application and its appearance:
Application information — This section lists editable information about the deployed application. You can also customize the standalone applications appearance by changing the application icon and splash screen. The generated installer uses this information to populate the installed application metadata. See Customize the Installer.
Command line input type options — This section lists selection of input data types for the standalone application. For more information, see Determine Data Type of Command-Line Input (For Packaging Standalone Applications Only).
Additional installer options — Edit the default installation path for the generated installer and selecting custom logo. See Change the Installation Path .
Files required for your application to run —Files required by the generated application to run. These files are included in the generated application installer. See Manage Required Files in Compiler Project.
Files installed for your end user — This section lists the files that are installed with your application. These files include:
The generated executable for the target platform
Additional runtime settings —This section lists platform-specific options for controlling the generated executable. See Additional Runtime Settings.
To generate the packaged application, click Package. In the Save Project dialog box, specify the location to save the project.
In the Package dialog box, verify that Open output folder when process completes is selected.
When the packaging process is complete, examine the generated output.
PackagingLog.txt— Log file generated by MATLAB Compiler.
Three folders are generated in the target folder location:
for_testing. For more information about the files generated in these folders, see Files Generated After Packaging MATLAB Functions Files Generated After Packaging MATLAB Functions (MATLAB Compiler SDK).
- MATLAB Coder (MATLAB Coder)