How to create an ExportedDefine global variable in Simulink for Code Generation?

For Code Generation from Matlab code the storage class 'ExportedDefine' allows to make a simulink variable appear in generated C-code as
#define var_name var_value
Is there a way to do this for a (constant) variable when generating code from a Simulink model?
Thanks for your help!

 採用された回答

Fangjun Jiang
Fangjun Jiang 2024 年 1 月 2 日
移動済み: Fangjun Jiang 2024 年 1 月 2 日

0 投票

Create a Simulink.Parameter, specify the storage class as "Define".

2 件のコメント

Thank you!
By creating a Simulink.Parameter in the base workspace like this:
z = Simulink.Parameter;
z.Value = uint32(10);
z.CoderInfo.StorageClass = 'Custom';
z.CoderInfo.CustomStorageClass = 'Define';
and referencing the parameter in the generated model like this:
I get a #define line in the generated code:
#define z 10U
Because I do not use the Parameter in the model itself but rather want to use it in other C-files, I need to add to the signal Param_z to the code mappings for the Parameter to be defined. Is there a more elegant way to do this?
Fangjun Jiang
Fangjun Jiang 2024 年 1 月 3 日
Your asked "Is there a way to do this for a (constant) variable when generating code from a Simulink model?"
If just want to have the .h file to do the #define, why not create the .h file directly, manually or create a script to write the text file.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Simulink Coder についてさらに検索

製品

リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by