How to set an array parameter with variable size for simulink model

1 visualización (últimos 30 días)
少冰
少冰 el 18 de Ag. de 2022
Respondida: Harsh el 29 de En. de 2025
I want to set an array parameter can be filled by the model user (who is also a developer) in the generated source file (like .h file in C language) and the length of this array is not limited. And then, I can get the size of this array in the model and traverse it.
For example, the model generate a source file as:
const int THE_ARRAY_PARAMETER[] = { 1, 2, 3 };
The model user can filled it, such as:
const int THE_ARRAY_PARAMETER[] = { 10, 20, 30, 40, 50 };
I can get the size of THE_ARRAY_PARAMETER and traverse it in the model.
But I don't know how to set this kinds of array parameter in the model and how to get the size of the array.

Respuestas (1)

Harsh
Harsh el 29 de En. de 2025
Hi,
You can use “Simulink.Parameter object to set the value of one or more block parameters in a model. To get or set the size of the “Simulink.Parameter” object you can use the “Dimensions” property.
The following code snippet creates a 1x5 array parameter-
THE_ARRAY_PARAMETER = Simulink.Parameter;
% Set the value of the parameter (array)
THE_ARRAY_PARAMETER.Value = [10, 20, 30, 40, 50];
% Set the data type
THE_ARRAY_PARAMETER.DataType = 'int32';
% Set the dimensions
THE_ARRAY_PARAMETER.Dimensions = [1, 5]; % 1x5 array
Use the following command to open documentation for “Simulink.Parameter” and learn more about it-
doc Simulink.Parameter

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by