How to add programmatically second input to Scope block in Simulink

조회 수: 3 (최근 30일)
Adrian Obuhov
Adrian Obuhov 2021년 10월 12일
댓글: Adrian Obuhov 2021년 10월 13일
Hello, I'm trying to add programmatically a second connection to the Scope block in Simulink, is there a way to do it ?
The error message:
Error using untitled4 (line 19)
Invalid Simulink object name: scope/2.
clc
open_system(new_system('test'));
add_block('simulink/Sources/Sine Wave','test/sine');
add_block('simulink/Commonly Used Blocks/Scope','test/scope');
add_line('test','sine/1','scope/1');
m = 0;
if m == 2
product = add_block('simulink/Commonly Used Blocks/Product','test/prod');
block1_handle = add_block('simulink/Commonly Used Blocks/Constant','test/const');
line2_handle = add_line('test','sine/1','prod/1');
line1_handle = add_line('test','const/1','prod/2');
line3 = add_line('test','prod/1','scope/2');
sim('test');
open_system('test/scope');
delete_block([product block1_handle line2_handle line1_handle line3]);
else
b1 = add_block('simulink/Commonly Used Blocks/Gain','test/gain');
l1 = add_line('test','sine/1','gain/1');
l2 = add_line('test','gain/1','scope/2');
sim('test');
open_system('test/scope');
delete_block([b1 l1 l2]);
end

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2021년 10월 12일
편집: Fangjun Jiang 2021년 10월 13일
specify 2 ports when you add the Scope block
add_block('built-in/Scope','test/scope','NumInputPorts', '2');

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by