Create a Simulink model with script

조회 수: 2 (최근 30일)
Metin
Metin 2014년 11월 19일
답변: Abhimanyu Singh 2017년 8월 7일
Hi, the basics of creating a Simulink model with scripts is clear when the mathworks is checked, my question is about to change the pamameters of a added block. E.g. to add a sin block
add_block('built-in/Sin', [gcs,'/Uref2'],...
'Position', [140 95 170 125],...
'SampleTime','0');
But how can I change amplitude and frequency also other parameters of the sin block, thanx for any comment in advance

채택된 답변

Erik
Erik 2014년 11월 19일
편집: Erik 2014년 11월 19일
Use
block = add_block(...);
to get the block handle. Set parameters using
set_param(block,param,value)
Where
param
is a string containing the parameter name, e.g. 'Amplitude' and
value
is the value the parameter should get (also a string!), e.g. '5'.
You can also set the parameters directly in the add_block(...,'Amplitude','5') command.
Search for "sine wave function" on this page for all possible parameters.
  댓글 수: 3
Erik
Erik 2014년 11월 19일
편집: Erik 2014년 11월 19일
See http://mathworks.com/help/simulink/slref/get_param.html for info on how to get all block parameters of a block using
get_param
You can then set them using
set_param
again.
Deleanu Cristian Nicolae
Deleanu Cristian Nicolae 2017년 8월 7일
add_block('built-in/Mux', [gcs,'/Mux1'],'Inputs','10','DisplayOption','bar');
The parameters are 'Inputs' 'DisplayOption'

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

추가 답변 (1개)

Abhimanyu Singh
Abhimanyu Singh 2017년 8월 7일
With Below mentioned code also you can add, set and get the newly added block details:
SimSubsystemObj = get_param(add_block(fullBlkSrcPath,[destinationpath,'/',blockname],... 'Position',[LeftPost BottomPos Width Height]),'Object'); %For Creating the Block and getting its handler%
set_param(SimSubsystemObj,'SampleTime','-1'); %For Setting block Value%

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by