Create a Simulink model with script

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

 Respuesta aceptada

Erik
Erik el 19 de Nov. de 2014
Editada: Erik el 19 de Nov. de 2014
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 comentarios

Metin
Metin el 19 de Nov. de 2014
I want to learn also how can I change any parameters of any block in Simulink, I mean how can I find the exact names of the parameters that belongs to any specific block in Simulink. E.g. to change number of inputs of a Mux block, or appearance as well. I have tried with
add_block('built-in/Mux', [gcs,'/Mux1'],...
'NumberofInputs','3','Position',pos);
but it doesn't work, what is the general way to find put all specific parameter names of a block to change with script, thanks a lot in advance
Erik
Erik el 19 de Nov. de 2014
Editada: Erik el 19 de Nov. de 2014
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.
add_block('built-in/Mux', [gcs,'/Mux1'],'Inputs','10','DisplayOption','bar');
The parameters are 'Inputs' 'DisplayOption'

Iniciar sesión para comentar.

Más respuestas (1)

Abhimanyu Singh
Abhimanyu Singh el 7 de Ag. de 2017

0 votos

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%

Categorías

Etiquetas

Preguntada:

el 19 de Nov. de 2014

Respondida:

el 7 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by