- 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.
- 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.
- 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.
how to change name of simulink blocks through matlab code
20 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
T.Nikhil kumar
on 14 Feb 2024
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:
Refer to the following documentation to understand about 'ReadRowNames' property of 'readtable' function:
Hope this helps you proceed further!
0 Comments
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!