MATLAB: Replace_block and load_system

load_systemreplace_blocksimulink

I have 2 questions, first being:
1. Can replace_block replace blocks with custom made blocks? I'm having some trouble with that so I don't know if it's supported or not. Can you tell replace block to only replace blocks on the top level or in a subsystem?
2. Can you run load_system and tell it not to save the changes you made? I want to use replace_block, run my model and exit leaving the model in its original state.

Best Answer

Yes, you should be able to replace blocks using replace_block with custom blocks as well. You will need to specify the full path of the library for custom blocks. Also, you might need to make sure that the custom library is loaded using load_library.
To have replace_block replace only inside a subsystem, you need to specify the path of the subsystem as the first argument (instead of the name of the top-level model).
To have it replace only blocks in the top level, use the 'SearchDepth' argument as follows:
>> replace_block('vdp', 'SearchDepth', 1, 'BlockType', 'Gain', 'Integrator')
If you are loading/opening a model, you also need to close it using close_system. You can tell close_system to not save changes by using the saveflag argument:
>> close_system('vdp', 0)