How to use signal name as variable name in generated code

39 ビュー (過去 30 日間)
Andrea Carignano
Andrea Carignano 2025 年 12 月 17 日 22:37
編集済み: Walter Roberson 2025 年 12 月 20 日 8:49
I have a simple model with an atomic subsystem block.
the signal after the subsystem "Function" is called "x" in the model.
The generated code for the step function is
void untitled1_step(void)
{
real32_T rtb_Gain;
/* Outputs for Atomic SubSystem: '<Root>/Function' */
/* Inport: '<Root>/In1' */
rtb_Gain = untitled1_Function(untitled1_U.In1);
/* End of Outputs for SubSystem: '<Root>/Function' */
/* Outport: '<Root>/Out2' incorporates:
* Bias: '<Root>/Bias'
*/
untitled1_Y.Out2 = rtb_Gain + 2.0F;
}
Embedded coder generate rtb_Gain variable.
However I would like to generate the x variable instead, so that the code became:
void untitled1_step(void)
{
real32_T rtb_Gain;
/* Outputs for Atomic SubSystem: '<Root>/Function' */
/* Inport: '<Root>/In1' */
x = untitled1_Function(untitled1_U.In1);
/* End of Outputs for SubSystem: '<Root>/Function' */
/* Outport: '<Root>/Out2' incorporates:
* Bias: '<Root>/Bias'
*/
untitled1_Y.Out2 = x + 2.0F;
}
Is there any general setting that I can activate to do this?
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 12 月 20 日 4:38
If you assign to x, why are you later using rtb_Gain + 2.0F instead of x + 2.0F ?
Andrea Carignano
Andrea Carignano 2025 年 12 月 20 日 6:59

It is a mistake, I correct the line, thank you

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

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2025 年 12 月 19 日 19:34
Double click the signal line and set the signal name as 'x'. That might be sufficient for your need.
Currently, the 'x' shown in your model looks like an annotation, not the signal name.
For more control, select the signal line, right click, select "Property" and set the signal line property.
One of the ways is to check "Name must resolve to signal object" and create a Simulink.Signal object in base workspace. Check the document for Simulink.Signal to learn more.
x=Simulink.Signal
x =
Signal with properties: Dimensions: -1 DimensionsMode: 'auto' Complexity: 'auto' SampleTime: -1 InitialValue: '' CoderInfo: [1×1 Simulink.CoderInfo] Description: '' DataType: 'auto' Min: [] Max: [] Unit: ''
  1 件のコメント
Andrea Carignano
Andrea Carignano 2025 年 12 月 19 日 21:47
編集済み: Andrea Carignano 2025 年 12 月 19 日 21:48

No, it is not correct, the signal name in my model is not an annotation, but the signal name. Moreover setting a simulink signal in the base workspace is not a robust solution. I need a general setting of the model. I need that every time I specify a signal name, embedded coder write this variable in the code. I do not understand the reason why this is not the default in embedded coder. In my opinion it would be the most intuitive way to get a readable code.

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

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by