필터 지우기
필터 지우기

Change all block names Simulinkin a List

조회 수: 1 (최근 30일)
Fabian
Fabian 2022년 3월 21일
답변: Saffan 2023년 7월 1일
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?

답변 (1개)

Saffan
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:

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by