Documentation Center

  • Trials
  • Product Updates

Simulink.SubSystem.convertToModelReference

Convert subsystem to model reference

Syntax

[success,mdlRefBlkH] = Simulink.SubSystem.convertToModelReference(subsys, mdlRef, 'opt1', 'val1', ... , 'optN', 'valN')

Description

[success,mdlRefBlkH] = Simulink.SubSystem.convertToModelReference(subsys, mdlRef, 'opt1', 'val1', ... , 'optN', 'valN') converts a subsystem to a referenced model. The function creates a new model, copies the contents of the subsystem into the model, sets the model configuration parameters, and configures the model's root-level Inport and Outport blocks. By default, the function then replaces the subsystem block with a Model block that references the new model. Alternatively, you can set the input option ReplaceSubsystem to create another, temporary model containing a Model block that references the new model.

This function does not convert all kinds of subsystems to referenced models. For details, see Which Subsystems Can You Convert?.

Converting a subsystem to a referenced model requires your model to have the following configuration parameter settings:

  • Configuration Parameters > Diagnostics > Data Validity > Signal resolution is set to Explicit only.

  • Configuration Parameters > Diagnostics > Connectivity > Mux blocks used to create bus signals is set to Error.

You can use the following commands to set these parameters to the values required by this function:

set_param(mdlName, 'SignalResolutionControl', 'UseLocalSettings');
set_param(mdlName, 'StrictBusMsg', 'ErrorLevel1');

When the conversion is successful, you might need to reconfigure the resulting model to meet your requirements. For details, see Integrate the Referenced Model into the Parent Model.

Input Arguments

subsys

Full name or handle of the subsystem to be converted

mdlRef

Name of the new model to convert the subsystem to

opt1, val1, ... , optN, valN

Zero or more pairs of options and values that control the conversion process. The options and values are:

'UseConversionAdvisor'

If you specify this option and set it to true, this function opens the Model Reference Conversion Advisor.

For details, see Run the Model Reference Conversion Advisor.

'AutoFix'

If you specify this parameter and set it to true, this function fixes all conversion issues that it can. The conversion process can generate error messages that you have to address by modifying the model.

'ReplaceSubsystem'

If you specify this parameter and set it to true, this function replaces the Subsystem block with a Model block that references the model created from the subsystem.

If you omit this option or set it to false, the function creates and opens a separate Simulink® Editor window with a model containing a Model block that references the model derived from the subsystem block.

'BusSaveFormat'

If you specify this option, the function saves any bus objects that it creates in a fiile. Specify the format of the file as either 'Cell' or 'Object'. Use cell array format to save the objects in a compact form.

If you omit this option, the function does not save bus objects to a file.

'BuildTarget'

If you specify this option, the function generates a model reference target. Specify the type of target as either 'Sim' or 'RTW'.

If you omit this option, the function does not generate a model reference target.

'Force'

If you specify this parameter and set it to true, this function returns some errors as warnings and continues with the conversion without fixing the errors. This allows you to use the function to do the initial steps of conversion, and then complete the conversion process yourself.

If you omit this option or set it to false, the function halts the conversion if an error occurs.

If you set the Force option to true, the success output argument can be true, but it is possible that the converted model does not produce the same results as the model did before you converted the subsystem.

Output Arguments

success

The value is true if the conversion completed successfully, and false otherwise.

If you set the Force option to true, the success argument can be true, but it is possible that the converted model does not produce the same results as the model did before you converted the subsystem.

mdlRefBlkH

Handle of the Model block that references the new model.

Tips

If the top model uses a data dictionary that does not have any unsaved changes, Simulink uses the data dictionary to save the bus objects that it creates as part of the conversion processing.

See Also

| |

Tutorials

Was this topic helpful?