主要内容

Publish Models to Speed Up Simulation and Code Generation

R2026b
Since R2026b

To speed up simulation and code generation for referenced models, you can create published models. These ready-to-run versions of Simulink® models contain build artifacts that Simulink unpacks and uses as needed. Simulink skips rebuild checks for published models, reducing model compilation and build overhead.

With published models, you can:

  • Lock down branches of a model hierarchy, preventing changes and rebuilds.

  • Reuse up-to-date build artifacts from Simulink cache files instead of regenerating them during publishing.

  • Share one published model that supports multiple platforms, compilers, releases, and code generation configurations.

  • Include supplemental files, such as instructions, test results, and code coverage reports.

  • Rename published models and create multiple published models from the same source model.

  • Log signals that you configure for logging before publishing.

  • Tune parameters.

  • Unpack the original data sources, such as data dictionaries.

  • Specify an alternate value source for external parameters.

Decide Whether to Publish a Model

Before you publish a model, consider whether publishing meets your requirements.

RequirementDeployment StrategySource of ContentsSimulink Implementation
Speed up simulation and code generation by locking down branches of a model hierarchy.Published modelPublished model file (.slxp)

Model block

Conceal intellectual property from third parties.Protected modelProtected model file (.slxp)

Model block

Enable simulation and integration in FMI-compliant tools outside Simulink.Functional mockup unit (FMU)FMU file (.fmu)

FMU block

To conceal intellectual property from third parties, see Protect Models to Conceal Contents.

To enable simulation and integration in FMI-compliant tools outside Simulink, see Export Simulink Models to Functional Mock-up Units (Simulink FMU Builder).

Published Model Requirements

Creating a published model requires a Simulink Coder™ license. Depending on the supported functionality you want to include, creation can require additional licenses and installations, for example:

  • To create a published model that supports an ERT-based system target file, you must have an Embedded Coder® license.

  • To create a published model that can run in Simulink Real-Time™, you must first install the Speedgoat® I/O Blockset and specify a system target file that corresponds to the target computer, such as speedgoat.tlc.

If you publish a model containing blocks that require another product license in addition to Simulink, using the published model in a separate MATLAB® session requires only a Simulink license.

Published Model Limitations

  • If the model contains variants, the published model includes only run-time variants and variants that are active during publishing.

  • If the model includes a noninlined S-function, use a unique name for the MEX file. If the name conflicts with a different MEX file on the MATLAB path, you cannot simulate the published model.

  • If the model uses callbacks, publishing does not preserve them.

Create a Published Model

To create a published model, use the Model Publisher.

  1. Open the Model Publisher using one of these options:

    • To publish the top model in a model hierarchy, in the Simulink Toolstrip, on the Simulation tab, click Publish.

    • To publish a referenced model, select the corresponding Model block. On the Model Block tab, in the Actions section, click Publish.

  2. Select the functionality that you want the published model to support.

    • Model reference simulation — Enables simulation of a model that references the published model in normal, accelerator, or rapid accelerator mode. This option is selected by default and read-only.

    • Model reference code generation — Enables C and C++ code generation for a model that references the published model.

  3. By default, all tunable parameters for simulation remain tunable in the published model. To limit which parameters remain tunable, on the Parameters tab, click Refresh. This compiles the model and generates a table of tunable parameters. In the table, clear the parameters that you want to be nontunable for simulation. Model arguments are selected by default and read-only because they are inherently tunable.

  4. To package supplemental files in the published model, such as instructions, test results, or code coverage reports, on the Add Supplemental Files pane, click Add Files.

    You do not need to include automatically identified model dependencies, such as data dictionaries. Publishing automatically includes these files. For more information, see Model dependencies.

  5. Optionally, on the Set Package Options pane:

    • Customize the published model filename, destination folder, and Model block icon.

      Tip

      To create multiple published models from the same source model, specify a unique filename each time you publish the model. This approach lets you distribute published models that represent different implementations, configurations, or revisions of the same source model.

    • Provide a custom tag that helps you trace the supported functionality in the published model to a commit or job number.

    • To generate a MATLAB script that lets you republish the model with the same interface configuration, supplemental files, and package settings, select Generate publishing script. The script contains the equivalent publishmodel command.

  6. Click Create.

After publishing, if a Model block specifies the filename without a file extension, the block references the new published model (.slxp) instead of the source model (.slx) based on file precedence.

To publish models with a continuous integration (CI) system, use the generated publishing script or write commands using the publishmodel function. Store .slxp files in a build archive area rather than under source control because they are binary files.

For more information on publishing from the command line, see publishmodel.

Support Multiple Environments and Configurations

A published model can contain build artifacts for multiple platforms, compilers, and model configurations. You can manage these artifacts by adding, removing, or merging them.

To create a published model that supports multiple platforms:

  1. Publish the same source model on each platform separately. For example, publish the model using both Windows® and Linux®.

  2. To combine the artifacts from different environments into one published model file, use the mergePublishedModels function.

For an example with a CI system, see Merge Published Models from Different Platforms.

To create a published model that supports multiple compilers:

  1. Change your default compiler or configure the model to use a different compiler.

    • To change your default compiler, in the MATLAB Command Window, enter mex -setup. For more information, see mex.

    • For code generation, you can configure the model for a different compiler by using the Toolchain model configuration parameter.

  2. To add the new artifact to the existing published model, use the addPublishedModelArtifact function.

To create a published model that supports multiple model configurations:

  1. Update the model configuration parameters. For example, specify a different System target file for the models in the hierarchy.

  2. To add the new artifact to the existing published model, use the addPublishedModelArtifact function.

For an example, see Support Multiple System Target Files in Published Model.

Modify Published Model Contents

After you publish a model, you can add or remove supported functionality and supplemental files without re-creating the published model.

  • To add supported functionality or supplemental files, use the addPublishedModelArtifact function. The source model must be available and configured for the functionality you want to add.

  • To remove supported functionality or supplemental files, use the removePublishedModelArtifact function.

Use Published Models

When a Model block specifies a model file with an extension such as .slx, the Model block references the source model.

To reference the published model, specify the published model filename with or without the .slxp extension. When a Model block specifies a filename without a file extension, and both a published model (.slxp) and the source model (.slx) with that name are in the same folder, the Model block references the published model.

For more information about referencing and using published models, see Reference Published Models.

See Also

Functions

Tools

Topics