Convert subsystem to model reference


[success,mdlRefBlkHs] = Simulink.SubSystem.convertToModelReference(subsys,mdlRefs)
[success,mdlRefBlkHs] = Simulink.SubSystem.convertToModelReference(subsys,mdlRefs,Name,Value)



Simulink.SubSystem.convertToModelReference(gcb,'UseConversionAdvisor',true) opens the Model Reference Conversion Advisor for the currently selected subsystem block.

[success,mdlRefBlkHs] = Simulink.SubSystem.convertToModelReference(subsys,mdlRefs) converts the specified subsystems to referenced models using the mdlRefs value.

For each subsystem that the function converts, it:

  • Creates a model

  • Copies the contents of the subsystem into the new model

  • Updates any root-level Inport, Outport, Trigger, and Enable blocks and the configuration parameters of the model to match the compiled attributes of the original subsystem

  • Copies the contents of the model workspace of the original model to the new model

Before you use the function, load the model containing the subsystem.


[success,mdlRefBlkHs] = Simulink.SubSystem.convertToModelReference(subsys,mdlRefs,Name,Value) uses additional options specified by one or more Name,Value pair arguments.


collapse all

Open the f14 model.


In the f14 model, select the Controller subsystem output signal, click the Simulation Data Inspector button arrow , and select Log Selected Signals.

In the Simulink® Editor, select the Controller subsystem. Then open the Model Reference Conversion Advisor from the command line.


Perform the conversion using the advisor.

Convert the Bus Counter subsystem to a referenced model named bus_counter_ref_model.

   'sldemo_mdlref_conversion/Bus Counter', ...
   'bus_counter_ref_model', ...
### Successfully converted Subsystem to Model reference block

Convert the two subsystems with one command.

{'f14/Controller','f14/Aircraft Dynamics Model'},...

Input Arguments

collapse all

Subsystems to convert, specified as a character vector, subsystem handle, or cell array of stings or array of subsystem handles.

For information about which subsystems you can convert, see Limitations on Subsystems That You Can Convert.


You cannot convert a parent subsystem a child of that subsystem at the same time.

Data Types: double

Referenced model names, specified as a character vector or cell array of character vectors. Each model name must be 59 characters or less.

If you specify a cell array of subsystems to convert, specify a cell array of referenced model names. Each model name corresponds to the specified subsystem, in the same order.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: Simulink.SubSystem.convertToModelReference...(engineSubsys,engineModelRef,'ReplaceSubsystem',true)

collapse all

If you set AutoFix to true, the function fixes all conversion issues that it can fix.

For issues that the function cannot fix, the conversion process generates error messages that you address by modifying the model.


If you set 'Force' to true, then the function does not automatically fix conversion issues.

Data Types: logical

If you set 'Force' to true, the function returns conversion errors as warnings and continues with the conversion without fixing the errors. This option allows you to use the function to do the initial steps of conversion and then complete the conversion process yourself.

If you set Force to true, then the function does not fix conversion issues, even if you set 'AutoFix' to true. However, the success output argument is true, regardless of whether any conversion errors occurred.

Compare simulation results before and after conversion, specified as true or false.

Before performing the conversion, enable signal logging for the subsystem output signals of interest in the model.

For the Simulink.SubSystem.convertToModelReference command, set:

  • 'CheckSimulationResults' to true

  • 'AbsoluteTolerance'

  • 'RelativeTolerance'

  • 'SimulationModes' to the same as the simulation mode as in the original model

If the difference between simulation results exceeds the tolerance level, the function displays a message.

Absolute signal tolerance for comparison, specified as a double. Use the option only if you set CheckSimulationResults to true.

Data Types: double

Relative signal tolerance for comparison, specified as a double. Use the option only if you set CheckSimulationResults to true.

Data Types: double

Name of file for storing conversion data, specified as a character vector. You can specify an absolute or relative path.

You can save the conversion data in a MAT-file (default) or a MATLAB® file. If you use a .m file extension, the function serializes all variables to a MATLAB file.

By default, the function uses a file name consisting of the model name plus _conversion_data.mat.

Replace subsystem blocks with Model blocks, specified as true or false. The Model block references the referenced model.

By default, the function displays the referenced models in separate Simulink Editor windows.

If you set the value to true, consider making a backup of the original model before you convert the subsystems. If you want to undo the conversion, having a backup makes it easier to restore the model.

If you set ReplaceSubsystem to true, the conversion action depends on whether you use the automatic fix options.

  • If you use the automatic fixes, then the conversion replaces the Subsystem block with a Model block unless the automatic fixes change the input or output ports. If the ports change, then the conversion includes the contents of the subsystem in a Model block that is inserted in the Subsystem block.

  • If you do not use the automatic fixes, then the conversion replaces the Subsystem block with a Model block.

Data Types: logical

Insert wrapper subsystem to preserve model layout, specified as true or false. When you convert a subsystem to a referenced model, you can have the conversion process insert a wrapper subsystem to preserve the layout of a model. The subsystem wrapper contains the Model block from the conversion.

The conversion creates a wrapper subsystem automatically if the conversion modifies the Model block interface by adding ports.

Data Types: logical

Simulation mode for Model blocks, specified as a 'Normal' or 'Accelerator'. The simulation mode setting applies to the Model blocks that reference the models that the conversion creates.

Model reference targets to generate.

  • 'Sim' — Model reference simulation target

  • 'RTW' — Code generation target

Output Arguments

collapse all

Conversion status. A value of 1 indicates a successful conversion.

If you set 'Force' to true, the function returns a value of 1 if the conversion completes. However, the simulation results can differ from the simulation results for the model before conversion.

Handles of created Model blocks, returned as a double or cell array.

Data Types: double


  • You cannot convert a parent subsystem a child of that subsystem at the same time.

  • Specifying multiple subsystems to convert with one command can save time, compared to converting each subsystem separately. The multiple-subsystem conversion process compiles the model one time.

  • If you specify multiple subsystems to convert, the conversion process attempts to convert each subsystem. Successfully converted subsystems produce referenced models, even if the conversions of other subsystems fail.

  • If you specify multiple subsystems, consider:

    • Specifying these 'Autofix', 'ReplaceSubsystem', 'CheckSimulationResults' name and value pairs, set to true.

    • In the model, setting a short simulation time.

  • Simulink uses the data dictionary to save the bus objects that it creates as part of the conversion processing when both these conditions exist:

    • The top model uses a data dictionary.

    • All changes to the top model are saved.

  • After you complete the conversion, update the model as necessary to meet your modeling requirements. For details, see Integrate the Referenced Model into the Parent Model.

  • Converting a masked subsystem can require you to perform additional tasks to maintain the same general behavior that the masked subsystem provided.

    If the subsystem that you convert contains a masked block, consider masking the Model block in your new referenced model (see Block Masks). Configure the referenced model to support the functionality of the masked subsystem.


    A referenced model does not support the functionality that you can achieve with mask initialization code to create masked parameters.

    For mask parameters, replace the mask parameters with model arguments (see Parameterize Instances of a Reusable Referenced Model):

    1. In the model workspace of the referenced model, create a variable for each mask parameter.

    2. In the Model Explorer, select the Model Workspace node. In the Contents pane, select the Argument check box to identify the variables as model arguments.

    3. In the new Model block, on the Arguments tab, in the Model arguments table, specify the values for the model arguments.

    For masked callbacks, icons, ports, and documentation:

    1. In the backup copy, open the Mask Editor on the masked subsystem and copy the content you want into the masked Model block.

    2. In the Mask Editor for the new Model block, paste the masked subsystem content.

Introduced in R2006a

Was this topic helpful?