Main Content

Control Subsystem Reference Programmatically

You can create a referenced subsystem, find available referenced subsystems in a model, change the referenced subsystem file in a block, and check the block diagram type of the file using a command-line interface.

Create a Referenced Subsystem

You can create a referenced subsystem using the new_system command:

new_system(subsystemfilename,'SubSystem')

Find Subsystem Reference in a Model

You can find if a model contains a referenced subsystem using the Simulink.findBlocksOfType function:

Simulink.findBlocksOfType(bdroot, 'SubSystem',...
'ReferencedSubsystem','.',Simulink.FindOptions('RegExp',1))

You can also use the find_system command:

find_system(bdroot, 'RegExp','on','BlockType','SubSystem','ReferencedSubsystem', '.')

Both return the number of Subsystem Reference blocks in the model. By default, find_system lists all the child blocks inside a subsystem reference instance.

If you do not want find_system to look inside a referenced subsystem, use find_system with LookInsideSubsystemReference set to off. By default, LookInsideSubsystemReference is set to on.

Change the Referenced File for a Subsystem

You can change the subsystem file being referenced in a Subsystem Reference block through command-line interface using the set_param command:

set_param(gcb, 'ReferencedSubsystem', '<subsystemfilename>')
This command changes the file being currently referenced by the Subsystem Reference block and replaces it with the new subsystem file you specify.

Check if the SLX or MDL File is a Subsystem Block Diagram Type

You can check if an SLX or MDL file is a subsystem block diagram type that can be placed in a Subsystem Reference block using any of these commands:

bdIsSubsystem(bdname)
This command returns logical 1 if bdname.slx is a Subsystem block diagram type and logical 0 if it is not. When using this command, make sure that bdname.slx is loaded.

get_param(bdname,'BlockDiagramType')

This command returns Subsystem if bdname.slx is a Subsystem block diagram type. When using this command, make sure that bdname.slx is loaded.

Simulink.MDLInfo(bdname)

This command gives the entire model information where the BlockDiagramType property is shown as Subsystem if bdname.slx is a Subsystem block diagram type.

See Also

Blocks

Related Topics