0
votes

I am writing a program that creates Simulink Models using commands in MATLAB. Currently, any subsystem that is added will be cleared immediately, then repopulated with the blocks we want in it. My question is how could I add a the While Iterator Block back into the subsystem after it has been cleared?

Sample code:

new_system('test_while_loop')
add_block('simulink/Ports & Subsystems/While Iterator Subsystem', 'test_while_loop/Subsystem_loop')
Simuink.SubSystem.deleteContents('test_while_loop/Subsystem_loop')
add_block('simulink/Ports & Subsystems/While Iterator', 'test_while_looop/Subsystem_loop/While Iterator')

This comes back with the error There is no block named 'simulink/Ports & Subsystems/While Iterator, even though the documentation for Simulink says that this block is contained within the Ports & Subsystems library. What do I need to change to be able to add this block?

1

1 Answers

2
votes

For built-in blocks you should use block type to add the block to your system. To identify the block type use

get_param(gcb, 'BlockType')

For the while iterator block this will return 'WhileIterator'. You can add this block to your system using

add_block('built-in/WhileIterator','test_while_looop/Subsystem_loop/While Iterator')

See documentation for add_block at https://www.mathworks.com/help/simulink/slref/add_block.html.