How do i automatically rename blocks following to the subsystem name?

30 ビュー (過去 30 日間)
Adrian Miguel Schiffer Gonzalez
Adrian Miguel Schiffer Gonzalez 2014 年 9 月 24 日
Hi all,
does someone knows how to write a script that renames every element in a subsystem of simulink(or of every element) following a pattern? The pattern could be for example then: #subsystemname#-#elementname# (result for example: 'Subsystem1-Scope1')
Is there somewhere a built in funcion or what are the commands to do so?
Thanks
Adrian

回答 (2 件)

Sreeram Mohan
Sreeram Mohan 2014 年 9 月 25 日
編集済み: Sreeram Mohan 2014 年 9 月 25 日
Hi Adrian,
Here is a small pointer to the solution.
%the following code below should return a list of the blocks in the subsystem
list_of_block_in_subsystem = find_system('modelName/subsystem', 'type', 'block');
%now on the obtained list one could just run a loop and set the name using set_params
for i = 1:length(list_of_block_in_subsystem)
if (i==1)
% cache the subsystem name
subsystem_name = get_param(list_of_block_in_subsystem{i}, 'Name');
else
old_name = get_param(list_of_block_in_subsystem{i}, 'Name');
new_name = [subsystem_name '-' old_name];
set_param(list_of_block_in_subsystem{i}, 'Name', new_name);
end
end
Hope this helps !!
Sreeram Mohan

Adrian Miguel Schiffer Gonzalez
Adrian Miguel Schiffer Gonzalez 2014 年 10 月 11 日
Hi Sreeam,
this helped me a lot! thank you.
Adrian

カテゴリ

Help Center および File ExchangeScopes and Data Logging についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by