Azzera filtri
Azzera filtri

Add data type conversion block in simulink model using script

5 visualizzazioni (ultimi 30 giorni)
I have simulink model where I have a lot of input signals. I need to add data type conversion block to all the input signals. How can i do that using script?

Risposte (1)

Fangjun Jiang
Fangjun Jiang il 28 Gen 2021
Do a loop, using these functions
  2 Commenti
rest12 il 29 Gen 2021
Modificato: rest12 il 29 Gen 2021
@Fangjun Jiang I am able to do it without loop. But with for loop I am getting error in the add_line about "Invalid Simulink object name". I am sharing my code.
%Without loop version
add_block('simulink/Commonly Used Blocks/Data Type Conversion', ['myModel','/Data Type Conversion']);
add_block('simulink/Commonly Used Blocks/Data Type Conversion', ['myModel','/Data Type Conversion1']);
add_line('myModel','Subsystem/1','Data Type Conversion/1','autorouting','on');
add_line('myModel','Subsystem/2','Data Type Conversion1/1','autorouting','on');
add_line('myModel','Data Type Conversion/1','Add/1','autorouting','on');
add_line('myModel','Data Type Conversion1/1','Add/2','autorouting','on');
%Loop version
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');
Fangjun Jiang
Fangjun Jiang il 30 Gen 2021
Your code looks good. Also a good practice to run line by line before running a loop.
>> strcat('Subsystem/',num2str(i),'/')
ans =
Not the same as 'Subsystem/1'

Accedi per commentare.


Scopri di più su Subsystems in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by