Repeating variable names in code generation

조회 수: 5 (최근 30일)
SergMariupol
SergMariupol 2025년 3월 25일
답변: Marie Anna NOVIELLO 2025년 3월 27일
I have charts of state flow. When generating a model in code I have a repetition of local variables. How can I avoid this?
An attempt to change the parameters of automatic assignment of names to local variables did not give a result
static boolean_T resultZC0;
static boolean_T resultZC1;
static boolean_T resultZC2;
static boolean_T resultZC0;
static boolean_T resultZC1;
  댓글 수: 2
SergMariupol
SergMariupol 2025년 3월 26일
편집: SergMariupol 2025년 3월 26일
The problem is the following.
If you have a charts state flow inside which is a simulink function and inside the simulink function and again state flows then local variables initialized in the latter are generated with duplicate names. It needs to be checked, but for now the output is like this
Altaïr
Altaïr 2025년 3월 27일
Including a sample model along with images of it would greatly aid the community in providing you with better assistance!

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

답변 (1개)

Marie Anna NOVIELLO
Marie Anna NOVIELLO 2025년 3월 27일
When MATLAB Coder or Stateflow generates code for a model with numerous states or outputs, you may encounter repetitious local variable names such as resultZC0, resultZC1, and so on. This is a typical issue. This occurs because the program automatically generates variables with similar names but distinguishes them with suffixes such as 0, 1, etc., which might result in code repetition.
Try to use Data Store Memory in Stateflow
(resultZC(0) = (some_condition); % This replaces resultZC0
resultZC(1) = (some_other_condition); % This replaces resultZC1)

카테고리

Help CenterFile Exchange에서 Decision Logic에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by