C code generated for variable size model interface

조회 수: 4 (최근 30일)
vivek patel
vivek patel 2022년 7월 21일
답변: Harsh 2025년 3월 28일
For one of the application, i need to have variable size input to the model. In the actual system the size of data would be changing i.e. either 1, 2,1000 etc. Hence i am trying to use the variable size.
I have changed the inport settings to say that it is a Variable Size. When i generate the c code with Embedded Coder, i see that the interface created for this inputs are still defined as uint8 a; and also one more struct with the size of the signal.
But i am not sure how can i pass the variable array from another code to the MATLAB code ? As the signal is still defined as a signle variable ?

답변 (1개)

Harsh
Harsh 2025년 3월 28일
To create a variable-sized input in Simulink, follow these steps:
  1. Configure the Inport Block: In the "Signal Attributes" tab of the Inport block, set "Variable-size signal" to "Yes." Specify the "Port dimensions" to indicate the maximum size for the Inport.
  2. Adjust Code Generation Settings: In the "Code Generation" settings, navigate to the "Interface" section and ensure that the "variable-size signals" option is checked.
  3. Generate Code: Use the "Embedded Coder" app to generate the code.
  4. Examine the Generated Code: In the generated code, open the "model.h" file to see how the input structure is handled. The header file will contain structures like:
/* External inputs (root inport signals with default storage) */
typedef struct {
real_T Inport[1000]; /* '<Root>/Inport' */
} ExtU_<modelName>_T;
/* External input sizes (for root inport signals with variable sizes) */
typedef struct {
int32_T Inport; /* '<Root>/Inport' */
} ExtUSize_<modelName>_T;
In the above code -
  • The external input structure (ExtU_<modelName>_T) declares an array "Inport[1000]", which serves as a buffer with a maximum capacity of 1000 elements for the input signal. You can specify this maximum size in the Simulink model by setting the "Port dimensions" as described earlier.
  • The external input sizes structure (ExtUSize_<modelName>_T) includes an integer field "Inport" that records the current number of valid elements in the input. For instance, if only 200 elements are valid, you would set "<modelName>_USize.Inport = 200".
I hope this explanation clarifies how you can set the input size in the generated code. If you have any further questions, feel free to ask!

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by