Borrar filtros
Borrar filtros

Change all block names Simulinkin a List

4 visualizaciones (últimos 30 días)
Fabian
Fabian el 21 de Mzo. de 2022
Respondida: Saffan el 1 de Jul. de 2023
Hi,
i have a model from another company to integrate in our own and we want to translate the model first. I dont speak the language and the translator does not know how to use simulink.
Is there a way to get all the names (Block names, Port lables) in a list form? Basically i would need a list of Blockhandle, Old Name. Then the translator can assign new names to the block handles and i can write them back. I know i can use the find_system to get the handle of a known block, but how to get the handle on any block and how to iterate through all?

Respuestas (1)

Saffan
Saffan el 1 de Jul. de 2023
I understand that you want to get a list of all the block names and port labels in the Simulink model as well as their handles. It can be achieved using “find_system” and “get_param” function as shown in the following code snippet:
% Open the model
model = 'BlockNames';
open_system(model);
% Get all block handles and names
blocks = find_system(model, 'LookUnderMasks', 'all', 'FollowLinks', 'on');
blockNames = get_param(blocks, 'Name');
You can iterate over the handles and replace the names with the translated names in the following way:
for i=1:size(blocks)
% get the new block name from the newBlockNames array which contains the translated block names.
translatedName = newBlockNames{i};
% update the block name using set_param function
set_param(blocks{i},'Name',translatedName);
end
The “set_param” function is used to modify parameters of Simulink blocks or models programmatically. Refer to these links for more information:

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by