Why is the "Remove internal data zero initialization" option removed when the code generation interface is specified to a C++ class?

조회 수: 7 (최근 30일)
I am attempting to code a simulink model using a C++ class as the code interface package. I have so far been able to generate the code, compile, and test it, however I have noticed some runtime issues.
I am using low pass filters in my model and noticed that early on in the program's execution the initial state of the internal delay blocks are not zero. Instead, they start with a random number associated with whatever was in memory at that time. I attempted to de-select the "Remove internal data zero initialization" option in the configuration parameters window to set their initial state to zero, however this option is greyed out.
Interestingly, if I change the initial state of the delay blocks to something non-zero, this creates initialization code which sets that value. This seems like an uneccessary limitation, as I cannot guarantee that the initial value of the variables is zero. Is there any work around to this which does not involve modifying the generated code?

답변 (1개)

Jasvin
Jasvin 2023년 3월 9일
편집: Jasvin 2023년 3월 9일
Unfortunately, if the "Remove internal data zero initialization" option is greyed out in the Simulink configuration parameters window, it means that this option is not available for your current configuration. This may be because you are using a C++ class as the code interface package, as certain options may not be compatible with this type of setup.
And there doesn't seem to be any workaround for this other than modifying the generated code to either add an initialization step or explicitly initialize the delay block.
  댓글 수: 1
SB
SB 2023년 3월 9일
Thank you for your response. I am using a C++ class as the code interface package.
When I explicitly initialize the delay block to a non-zero value, that initialization becomes generated in the initialize() function. However, explicitly initializing the delay block to 0 becomes optimized out of the generated code. I am unsure how the latter is incompatible with a class interface.

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by