How can I get the names and properties of multiple subsystems?

34 visualizaciones (últimos 30 días)
JinWook Park
JinWook Park el 29 de Nov. de 2024 a las 6:19
Respondida: Jacob Mathew el 29 de Nov. de 2024 a las 7:49
Hello
I would like to get the names of the Subsystems in Simulink and the descriptions of their properties.

Respuesta aceptada

Angelo Yeo
Angelo Yeo el 29 de Nov. de 2024 a las 6:51
Check this out.
% Open model
modelName = 'myModel';
load_system(modelName);
% Find all subsystems in the model
subsystems = find_system(modelName, 'BlockType', 'SubSystem');
% print all the name of subsystems
for i = 1:length(subsystems)
subsystemName = get_param(subsystems{i}, 'Name');
fprintf('Subsystem %d: %s\n', i, subsystemName);
end
Subsystem 1: A_Fnc Subsystem 2: B_Fnc Subsystem 3: C_Fnc
% To get model description
modelDescription = get_param(modelName, 'Description');
% print out the model's description
fprintf('Model Description: %s\n', modelDescription);
Model Description: Hello !!

Más respuestas (1)

Jacob Mathew
Jacob Mathew el 29 de Nov. de 2024 a las 7:49
Hey JinWook,
You can use the find_systemfunction to find a specific block, in this case, all the subsystem blocks. Once you have them, you can use the get_param function to get the descriptions of each block iterating over all subsystems you have.
Consider the attached example model called ‘testModel’ that has 3 subsystems and their descriptions. The following code gets all the subsystems and iteratively, all of their descriptions:
% Your Simulink model name
modelName = 'testModel';
% Load the model if its not already open
load_system(modelName);
% Finding all subsystems of the model
subsystems = find_system(modelName, 'BlockType', 'SubSystem');
for i=1:length(subsystems)
% all the description's of the model
description = get_param(subsystems{i}, 'Description');
fprintf('Subsystem Name: %s\n', subsystems{i});
fprintf('Subsystem Description: %s\n', description);
end
Subsystem Name: testModel/Subsystem1
Subsystem Description: Description1
Subsystem Name: testModel/Subsystem2
Subsystem Description: Description2
Subsystem Name: testModel/Subsystem3
Subsystem Description: Description3
You can learn more about find_system and get_param in the links below : https://www.mathworks.com/help/releases/R2022b/simulink/slref/find_system.html

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by