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 (Simulink).
In this example, create a MATLAB® function to simulate the model
with the values of
Simulink.SimulationInput. Save the script as
deployParameterTuning.m on the MATLAB path.
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 deployedScriptSaveResults 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_deploy'); in = in.setVariable('Mb', mb); in = simulink.compiler.configureForDeployment(in); out = sim(in); save(oName, 'out'); end
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
applicationCompiler at 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 is 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 (MATLAB Compiler).
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) (MATLAB Compiler).
Additional installer options — Edit the default installation path for the generated installer and selecting custom logo. See Change the Installation Path (MATLAB Compiler) .
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 (MATLAB Compiler).
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
See Specify Files to Install with Application (MATLAB Compiler).
Additional runtime settings —This section lists platform-specific options for controlling the generated executable. See Additional Runtime Settings (MATLAB Compiler).
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
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 (MATLAB Compiler)
Files Generated After Packaging MATLAB Functions (MATLAB Compiler SDK).