How to get referenced subsystem block name and SLX file path for all the Subsystem References in a model?

3 views (last 30 days)

I am using MATLAB R2023b and I have top level model "topModel.slx". There is a "Referenced Subsystem" block inside this model, named "Subsystem", while the "Referenced Subsystem" file is saved as "testRefSubsystem.slx".
Is there a function that allows users to retrieve the file paths or model names of all of the "Referenced Subsystem" blocks by passing in the name of a top level model (such as the function "find_mdlref" returning the names of "Referenced Models")? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Apr 2024 at 0:00
To get the name of the "Referenced Subsystem" blocks, you can use the "get_param" function with the Subsystem parameter "ReferencedSubsystem". For more information on the parameter, please see below: 
To return the file paths to the SLX files, you can use the function "which". For more information on the function, please see below:
Assuming the name of your model is "TopModel", you can search for the "Subsystem" blocks that have input for the "ReferencedSubsystem" parameter using the "find_system" function. In this example, the "blks" variable stores the names of the referenced subsystem:
load_system('topModel');
blks = find_system('topModel','RegExp','on','BlockType','SubSystem','ReferencedSubsystem','.');
Then, you can find the file paths of the referenced subsystems with the "which" function. This example stores the paths in the variable "filePaths": 
refBlks = get_param(blks,'ReferencedSubsystem');
for i = 1:length(refBlks )
filePaths{i} = which(refBlks {i});
end

More Answers (0)

Categories

Find more on Model References in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!