Adding a masked subsytem to a model from script.

조회 수: 5 (최근 30일)
Michael Joslin
Michael Joslin 2011년 8월 25일
I am writing a program that automates the building of a simulink system. However when I try the following command:
add_block('built-in/Compare To Constant',[sys,'/compare'],'relop','~=','const','realmax(single)','Position',[100 275 200 325])
I get an error stating that a block compare to constant block doesn't exist. After digging a little I discovered that compare to constant is actually a masked subsystem. So my question is is there a way to add compare to constant, or a similar masked subsystem block, to a model from script directly or do I need to re-create the subsystem and then mask it in the code?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 25일
This is a little tricky. Right click the Simulink library at the library browser, choose 'Open the Simulink library'. Then double click the "Logical and Bit operations", select the "Compare to Constant" block.
Go to MATLAB Command Window, type source=gcb, you will see the full path of the block. It contains carriage returns.
Assume you have a new model called "untitled" open, run the line and you will see the block added.
add_block(source,'untitled/block')
  댓글 수: 2
Guy Rouleau
Guy Rouleau 2011년 8월 25일
Good catch for the CR Fangjun.
If you want to build the string from scratch, you can use sprintf and "\n" for the carriage return... something like:
source = sprintf('Compare\nTo Constant');
Fangjun Jiang
Fangjun Jiang 2011년 8월 26일
Or use source=['Compare',char(10),'To Constant'].
I thought the main issue is the 'built-in'. add_block(source,destination) always works with the full path of source. 'built-in' seems to work only for those elemental blocks, such as Gain, Sum.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by