Clear Filters
Clear Filters

How can I create a Simulink reference subsystem which contains the contents of a library, programmatically?

2 views (last 30 days)
I am working entirely programmatically.
I have a Simulink library whose top layer contains a masked block. I want to create a reference subsystem (not a subsystem within a model, but a subsystem which may be saved as a file) whose entire contents is that of the masked block within the library. The reference subsystem is to be placed in the third layer of my system as "Model" using the command below:
add_block('simulink/Ports & Subsystems/Subsystem Reference','System/FirstObject/SecondObject/Model')
Thanks for your help!

Answers (1)

Aniketh
Aniketh on 25 Jun 2023
To programmatically create a Simulink reference subsystem that contains the contents of a library, first load the system:
Get the handle of the masked block within the library using the find_system function. You need to provide the library name and the name of the masked block:
maskedBlock = find_system('library', 'MaskType', 'maskedBlockType');
Create the reference subsystem using the add_block function, specifying the masked block's handle and the desired location for the reference subsystem within your system:
refSubsystem = add_block(maskedBlock, 'System/FirstObject/SecondObject/Model');
Save the reference subsystem as a separate file using the save_system function, providing the reference subsystem's handle and the desired file path:
save_system(refSubsystem, 'path/to/referenceSubsystem.slx');
Replace 'path/to/referenceSubsystem.slx' with the desired file path where you want to save the reference subsystem.
This should work hopefully

Categories

Find more on Automotive Applications in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!