Using replace_block with custom simulink library
조회 수: 20 (최근 30일)
이전 댓글 표시
I am trying to create a script that goes through old models looking for outdated versions of custom library blocks and automatically updates them to the newest versions. To do this I am trying to utilize the commands find_system and replace_block. This first to identify which outdated blocks exist in the model, and the second to replace them with the new blocks. However, when attempting to utilize these functions, they report
Invalid NewBlock (<PeakandHold>) passed to
REPLACE_BLOCK.
Try built-in/BLOCKTYPE or a valid block name.
These blocks are all located in a custom library named PME_Library and then organized into folders. When using replace block on just the block name to a built in block type works, but doing it based on block type or when trying to replace the target block with a custom library block results in this error. How do I get these functions to use blocks inside the custom library.
댓글 수: 0
답변 (1개)
tkarg
2021년 12월 9일
Maybe it is a bit late for a response but the solution can be helpful for anybody reading.
You need to use path of your custom block -not block type, in the replace_block function. Following code replaces Gain blocks in the model with your custom block.
replace_block(model, 'BlockType', 'Gain', 'your_library/your_block_name');
Another thing, your Simulink library should be loaded into the memory when you are using a block from it (in replace_block or wherever). You can do this by opening it through Simulink, or with the following command in Matlab script:
load_system your_library
These are valid at least for 2021a.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!