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 .
if the models contain non-deployable mask initialization code, there may be errors while
tuning the parameter. these models are deployable but are limited in their functionality due
to them containing certain parameters that cannot be tuned during runtime. you can recompile
the model with new values for such parameters. you can use the
simulink.compiler.gettunablevariables
function to figure out which
variables in the model are tunable.
when simulating the top model, to tune referenced workspace variables inside nested model references, you can mark the referenced variables as model arguments and pass their instance specific values from the top model via a model block. alternatively, you can define all the variables in all the nested models in the base workspace.
prepare a script to deploy simulations with parameter tuning
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.
prepare a function to deploy
create a function called deployparametertuning
containing the code
shown below. this code creates a simulink.simulationinput
object for
the model sldemo_suspn_3dof
. 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
.
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
deployed app.
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
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
. click open.the function
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.
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:
a generated
readme.txt
filethe 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_redistribution
,for_redistribution_files_only
, andfor_testing
. for more information about the files generated in these folders, see (matlab compiler sdk).
see also
apps
- (matlab coder)
functions
- | | | | |