How can I use custom storage class for defining global variables in matlab code for code generation?

19 views (last 30 days)
I was able to create my own package of storage class and its application on the simulink model.
Now i want to use the package for matlab coder as i am trying to generate code from matlab code.
How can i approach for this?

Answers (1)

Abhas
Abhas on 28 Oct 2024 at 4:42
To use a custom Storage Class in MATLAB, follow these steps:
  1. Open your Simulink model.
  2. Go to the C Code tab and click on Code Interface in the Embedded Coder section.
  3. Select Embedded Coder Dictionary & navigate to Storage Classes.
  4. Click Add and define the name and properties of your new storage class.
  5. Now, open Code Mappings via Code Inteface > Code Mappings.
  6. Select the data elements to customize.
  7. Choose your custom storage class from the Storage Class dropdown.
You should follow the guidelines for Creating a Storage Class to avoid any issues while creating and configuring:
  1. Initiate the creation of a storage class and save it using all default settings.
  2. Ensure that it appears in the code mappings—verify its presence.
  3. Assign the storage class to the desired object, such as specific Inport(s).
  4. Begin customizing the newly created storage class.
  5. If you mistakenly select an incorrect value for a property, the Code Generator will flag errors, helping you identify the root cause more easily. This approach allows you to make incremental customizations while performing code generation.
You may refer to the following documentation link for more details on creating custom Storage Class:

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!