필터 지우기
필터 지우기

how to change name of simulink blocks through matlab code

조회 수: 12 (최근 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 CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by