フィルターのクリア

how to change name of simulink blocks through matlab code

9 ビュー (過去 30 日間)
Vibhu Mehta
Vibhu Mehta 2021 年 12 月 13 日
回答済み: T.Nikhil kumar 2024 年 2 月 14 日
exl = actxserver('excel.application');
exlWkbk = exl.workbooks.Add;
new1= readtable('names.xlsx');
list_of_block_in_subsystem = find_system('Auto_Script','type', 'block');
for i = 1:length(list_of_block_in_subsystem)
old_name = get_param(list_of_block_in_subsystem{i},'Name');
new_name = new1.aa{i};
set_param(list_of_block_in_subsystem{i}, 'Name', new_name);
end
%code is not running completely only half of the names changes and also code is executing only ones.

回答 (1 件)

T.Nikhil kumar
T.Nikhil kumar 2024 年 2 月 14 日
Hello Vibhu,
I get that you are trying to rename the blocks in your Simulink model using a MATLAB script. Based on your code, here are a few observations which could be reasons why your MATLAB code is not working correctly:
  1. When you use the ‘readtable’ command to read from ‘.xlsx’ file, you should set the ‘ReadRowNames’ property to false when the first column of the region to read contains data, not the row names for the table. Your model contains 27 blocks and the excel sheet contains 27 corresponding new names. You must use ‘readtable’ with this property set for correct mapping of new names for blocks.
  2. Also, you need to keep in mind that renaming a block can potentially break links to this block if other blocks or scripts reference it by its old name. Ensure that you update all references accordingly.
  3. You are creating an Excel server but not using it in the code you provided. If you intend only to read from an Excel file, you can use ‘readtable’ directly without creating an Excel server.
Refer to the following documentation to understand about 'ReadRowNames' property of 'readtable' function:
Hope this helps you proceed further!

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by