user1761275
user1761275

Reputation: 7

MATLAB add_line with for loop gives invalid Simulink object name error

I have MATLAB Simulink model where "Subsystem" is connected with "Add" block. I want to add Data type conversion block in between Subsystem and Add block using script. I implemented as shown in the code below. But I am getting error Invalid Simulink object name in the add_line of the code.

for i = 1:n;
      delete_line('myModel',strcat('Subsystem/',num2str(i),'/'), strcat('Add/',num2str(i)));
      add_block('simulink/Commonly Used Blocks/Data Type Conversion', strcat('myModel','/Data Type Conversion',num2str(i)));
      add_line('myModel', strcat('Subsystem/',num2str(i),'/'), strcat('Data Type Conversion',num2str(i)),'autorouting','on');                                     
      add_line('myModel',strcat('Data Type Conversion',num2str(i),'/1'),strcat('Add',num2str(i)),'autorouting','on'); 

Upvotes: 0

Views: 915

Answers (1)

scotty3785
scotty3785

Reputation: 7006

You aren't specifying the destination port number for the Data Type Conversion block.

Try

add_line('myModel', strcat('Subsystem/',num2str(i),'/'), strcat('Data Type Conversion',num2str(i),'/1'),'autorouting','on');

You may also need to do this for the line to the add block as I'm guessing it has multiple ports too.

Upvotes: 0

Related Questions