Why Simscape variables are hard-coded in the generated code?

4 views (last 30 days)
I am generating code for a physical network that includes a 'Constant Volume Chamber (G)'. I need to modify the initial pressure externally, but I cannot find an option to switch the configuration from 'Compile-time' to 'Run-time'. As a result, the exported C++ code has the initial pressure value hardcoded based on the current variable value in the Workspace.
Is there a way to configure the initial pressure at 'Run-time'?
If yes, could you please provide guidance on how to achieve this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Jul 2023
The variables listed in the "Variables" settings are automatically configured as "Run-time" tunable if they are associated with a variable in the MATLAB Workspace. This is why there is no option to explicitly configure them to "Run-time" from "Compile-time".
As an example, you can adjust the initial pressure of the "Constant Volume Chamber (G)" by assigning it to a variable (such as the "InitialPressure," as shown in the screenshot below), which is specified in the Base Workspace:
 
Furthermore, it is essential to ensure that the "Default parameter behavior" under Configuration Parameters > Code Generation > Optimization is configured as "Tunable" before proceeding with code generation. This way, the Simscape variables can be modified at runtime. 
 
For additional information on this topic, you can consult the documentation page below:

More Answers (0)

Categories

Find more on Run-Time Parameters in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!