How we have define a parameter for Code Generation

조회 수: 1 (최근 30일)
Ali
Ali 2024년 8월 22일
편집: Shubham 2024년 8월 22일
I've added 2 constant blocks.
As you can see the model explorer defines.
I couldn't understand, if we add outport the constant name is generated in code, if there is no outport for parameter2 it will not generated in C code.
How I solve the problem.
Generated Code:
/* Definition for custom storage class: Define */
#define parameter1 1.0 /* Referenced by: '<Root>/Constant' */
Thank you.

답변 (1개)

Shubham
Shubham 2024년 8월 22일
Hi Ali,
When working with Simulink models and generating C code, only the parameters that are actively used in the mode - like those connected to an "Outport", are typically included in the generated code. This behaviour is because Simulink's Code Generation optimizes the code by omitting unused variables or constants to reduce memory usage and improve efficiency.
In your case, you’ve noticed that the "Constant" block without an "Outport" doesn’t result in the parameter being included in the generated C code. The generated code only includes "parameter1" because it is referenced by an "Outport". The "model_name.h" file shows this as comment in generated C code:
/*-
* These blocks were eliminated from the model due to optimizations:
*
* Block '<Root>/parameter2' : Unused code path elimination
*/
For more information on how dead code paths and unused blocks are eliminated from generated code, refer to the following documentation link:
Hope it helps.
  댓글 수: 2
Ali
Ali 2024년 8월 22일
Hi, Shubham,
Thanks for reply,
in which cases it does not optimize?
Can I turn off the optimization to test under some conditions?
Thanks.
Shubham
Shubham 2024년 8월 22일
편집: Shubham 2024년 8월 22일
Hi Ali,
For Code Generation, block reduction optimization removes all diagram branches terminating in sink blocks that do not participate in code generation.
To turn off the optimization, navigate to "Model Settings" -> "Simulation Target" and uncheck "Block reduction" property.
For more information on "Block reduction", refer to the following documentation link:
If you have any other query, feel free to comment.
Thanks

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

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by