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

3 次查看(过去 30 天)

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")? 

采纳的回答

MathWorks Support Team
MathWorks Support Team 2024-4-5,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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model References 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by