How to use a script to select drop-down menu options of component in Simulink?

Hello! I am using a simulator developed by another person in Simulink, and I want to test my simulation under different input parameters. The script I made is able to modify the values of the input boxes, but not to select options such as component names from drop-down menus. Is there any way to add this feature to my script?
When trying to make this in the same way as I did with numerical values for the boxes, using the set_param function, I got the following error:
??? Error using ==> set_param
Component block (mask) does not have a parameter named 'ComponentName'
Thank you!!

Respuestas (2)

It is unlikely. This is dependent on that "simulator developed by another person in Simulink". Either it provides an API for you to do that, or you have the source code to figure out an entry point.
If the entity you want to do set_param on is a block, then you can get a lot of information from DialogParameters.
The following code shows an example of programatically getting all the valid choices for a Product Blocks "Integer rounding mode" parameter.
mdl = 'foo';
new_system(mdl)
myBlk = [mdl,'/myProduct'];
add_block('built-in/Product',myBlk)
dp = get_param(myBlk,'DialogParameters')
dp = struct with fields:
Inputs: [1×1 struct] Multiplication: [1×1 struct] CollapseMode: [1×1 struct] CollapseDim: [1×1 struct] InputSameDT: [1×1 struct] OutMin: [1×1 struct] OutMax: [1×1 struct] OutDataTypeStr: [1×1 struct] LockScale: [1×1 struct] RndMeth: [1×1 struct] SaturateOnIntegerOverflow: [1×1 struct] SampleTime: [1×1 struct]
dp.RndMeth
ans = struct with fields:
Prompt: 'Integer rounding mode:' Type: 'enum' Enum: {'Ceiling' 'Convergent' 'Floor' 'Nearest' 'Round' 'Simplest' 'Zero'} Attributes: {'read-write' 'read-only-if-compiled' 'dont-eval' 'link-instance'}
validChoicesForIntegerRoundingMode = dp.RndMeth.Enum
validChoicesForIntegerRoundingMode = 1×7 cell array
{'Ceiling'} {'Convergent'} {'Floor'} {'Nearest'} {'Round'} {'Simplest'} {'Zero'}

2 comentarios

Hi Andy,
I have a similar issue.
I'm using Matlab 2017a.
I'm using a UDP send block and want to programmatically change the local IP address.
I specify the UDP interface through a UDP configure block .
I need to comment/uncomment the UDP configure block and the UDP send block depending on specific configurations (also programmatically).
My issue is, when uncommenting the UDP configure block and the UDP send block, the enum for the parameter seemse not to be updated, i.e., get_param does not return the IP specified in the UDP configure block.
I tried different ways to "force" the block update (e.g., saving the model). Is there any way to do so?
set_param(modelName, 'SimulationCommand', 'update')

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2007b

Preguntada:

el 19 de En. de 2024

Comentada:

el 12 de Feb. de 2026

Community Treasure Hunt

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

Start Hunting!

Translated by