Change all block names Simulinkin a List
2 ビュー (過去 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!