Customizing Generated Code File Names in Simulink?

21 views (last 30 days)
审言
审言 on 17 Mar 2025
Answered: Harsh on 24 Mar 2025 at 10:03
My model is named Test, and in Simulink's Code Generation -> Code Placement, the automatically generated file naming rules are as follows:
  • Header file: $R$E
  • Source file: $R$E
  • Data file: $R_data
The generated files include:
  • Test.c
  • Test.h
  • Test_types.h
  • Test_private.h
When I replace $R with myModel, the generated files become:
  • myModel.c
  • myModel.h
  • myModeltypes.h
  • myModelprivate.h
I noticed that the underscore (_) disappeared in the last two files.
Is there any way to adjust the generated code file names so that they are different from the main model name?

Answers (1)

Harsh
Harsh on 24 Mar 2025 at 10:03
You can use a “Custom token text” to modify the name of the header, source and data files generated during code generation. Please follow the below steps to create and use a custom token:
  • In the Code Generation > Identifiers section, specify the “custom token text” in “advanced parameters”
  • In the Code Generation > Code Placement section, you can use the custom token by entering “$U” in “Auto-generated file naming rules”
  • Note that "$E" is mandatory for header and source files, representing instances for various file types such as dt, private, types, etc.
  • After making the above changes, you should be able to see “CustomToken” in your filenames as
You may refer to the following documentation page for “Custom token text” - https://www.mathworks.com/help/releases/R2024b/ecoder/ref/customtokentext.html

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!