Control Subsystem Reference Programmatically - MATLAB & Simulink (original) (raw)
Main Content
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 theSimulink.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 theset_param
command:
set_param(gcb, 'ReferencedSubsystem', '')
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:
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 thatbdname.slx
is loaded.
This command gives the entire model information where theBlockDiagramType
property is shown as Subsystem
ifbdname.slx
is a Subsystem block diagram type.