Documentation

Simulink.SubSystem.convertToModelReference

Convert subsystem to model reference

Syntax

  • Simulink.SubSystem.convertToModelReference(gcb,'UseConversionAdvisor',true) example
  • [success,mdlRefBlkH] = Simulink.SubSystem.convertToModelReference(subsys,mdlRef)
  • [success,mdlRefBlkH] = Simulink.SubSystem.convertToModelReference(subsys,mdlRef,Name,Value) example

Description

example

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

[success,mdlRefBlkH] = Simulink.SubSystem.convertToModelReference(subsys,mdlRef) converts the specified subsystem to a referenced model using the mdlref value.

The function:

  • 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.

example

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

Examples

collapse all

Open the Model Reference Conversion Advisor

Open the f14 model.

open_system('f14');

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

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

Simulink.SubSystem.convertToModelReference(gcb,'UseConversionAdvisor',true);

Perform the conversion using the advisor. For details, see Convert a Subsystem to a Referenced Model.

Convert Subsystem to Referenced Model

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

open_system('sldemo_mdlref_conversion');
[success,mr_handle] = Simulink.SubSystem.convertToModelReference(...
   'sldemo_mdlref_conversion/Bus Counter', ...
   'bus_counter_ref_model', ...
   'AutoFix',true,...
   'ReplaceSubsystem',true,...
   'CheckSimulationResults',true);
success =

     1

>> mr_handle

mr_handle =

   79.0018

Related Examples

Input Arguments

collapse all

subsys — Subsystem to convertstring | subsystem handle

Subsystem to convert, specified as a string. Specify either the full path to the subsystem or specify the subsystem handle.

The subsystem must be one of these kinds of subsystem:

  • Atomic

  • Function-call

  • Triggered

  • Enabled

The Configuration Parameters > Diagnostics > Data Validity > Signal resolution parameter must be set to Explicit only. To do set that parameter programmatically, use this command, substituting your model name for myModelName.

set_param(myModellName,'SignalResolutionControl','UseLocalSettings');

Data Types: double

mdlRef — Referenced model namestring

Referenced model name, specified as a string. The model name must be 59 characters or less.

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)

'DataFileName' — Name of file for storing conversion datastring

Name of file for storing conversion data, specified as a string. 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.

'AutoFix' — Fix all conversion issues that can be fixed automaticallyfalse (default) | true

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.

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

Data Types: logical

'ReplaceSubsystem' — Replace Subsystem block with Model blockfalse (default) | true

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

By default, the function displays the referenced model in a separate Simulink Editor window.

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

Data Types: logical

'BuildTarget' — Model reference target to generate'Sim' | 'RTW'

Model reference target to generate, specified as a string.

  • 'Sim' — Model reference simulation target

  • 'RTW' — Code generation target

'Force' — Complete conversion even with errorsfalse (default) | true

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 truee, regardless of whether any conversion errors occurred.

'SimulationModes' — Simulation mode for Model block'Normal' (default) | 'Accelerator'

Simulation mode for Model block, specified as a 'Normal' or 'Accelerator'. The simulation mode setting applies to the Model block that references the model that the conversion creates.

'CheckSimulationResults' — Compare simulation results before and after conversionfalse (default) | true

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.

'AbsoluteTolerance' — Absolute signal tolerance for comparison'1e-06' (default) | double

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

Data Types: double

'RelativeTolerance' — Relative signal tolerance for comparison'1e-06' (default) | double

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

Data Types: double

Output Arguments

collapse all

success — Conversion status1 | 0

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.

mdlRefBlkH — Handle of created Model blockhandle of Model block

Handle of created Model block.

Data Types: double

More About

collapse all

Tips

  • 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 Masking). Configure the referenced model to support the functionality of the masked subsystem.

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

    For masked parameters:

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

    2. In the Model Explorer, select the Model Workspace node. In the Dialog pane, in the Model arguments parameter, enter the variables that you want for model arguments.

    3. In the new Model block, for the Model arguments parameter, 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?