Change all block names Simulinkin a List
7 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Saffan
2023-7-1
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!