- Open Signal Properties:
- Right-click on the signal line in your Simulink model.
- Select "Properties" from the context menu.
- Enable Test Point:
- In the Signal Properties dialog, go to the "Logging and accessibility" section.
- Check the Test Point option.
How can I force variables that are optimized away to appear in the generated code using Coder products?
11 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2025-7-1
回答: MathWorks Support Team
2025-7-10
I have a model in Simulink for which I would like to generate code. In the generated code, I find that some of the variables are optimized away by the coder. These variables are outputs of a lower-level subsystem and are not used by the higher-level subsystem, but they contain information that is crucial for debugging.
How can I force these variables to appear in the generated code?
采纳的回答
MathWorks Support Team
2025-7-1
There are a few methods you may consider:
1) Mark the signal as a Test Point
If the name of the signal does not appear in the generated code, try marking it as a Test Point by following these steps:
This approach is particularly useful when you want to retain intermediate signals for debugging, testing, or code generation purposes.
2) Name the signal
Try naming the signal by double-clicking the signal line in your Simulink model.
3) Use "Outport" blocks instead of "Terminator" blocks
If the outputs of the lower-level subsystem are terminated by a "Terminator" block, replace that with an "Outport" block. This forces the upper-level subsystem to "use" the signal, so the signal will appear in the generated code. Note that this will alter the structure of the model, especially for large models.
4) Change the Sampling Time property of "Constant" blocks
If you have "Constant" blocks, make sure the sampling time is "-1" instead of "Inf". The coder may treat the signal as a block constant if the Sampling Time is set to "Inf".
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Configure Simulation Conditions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!