How can I configure the Matlab coder to generate very simple C-code?

11 ビュー (過去 30 日間)
Glen Tallarek
Glen Tallarek 2024 年 10 月 29 日
コメント済み: Glen Tallarek 2024 年 10 月 29 日
I have a relatively simple Simulink model that I would like to generate C-code for. When I run the code builder, I get an assortment of files that include many other functions and RAM structures that make reading and understanding the code more difficult. Is there a way to adjust the configuration parameters to generate a much simpler code with fewer files? And/or are there ways to configure the signals that would control how they are implemented in the code? Ideally I would like to see something that would resemble the "hand code" files that I would generate.

採用された回答

Abhas
Abhas 2024 年 10 月 29 日
To simplify the generated code to make it more straightforward and closer to hand-written code here are some suggestions:
  1. Choose the Right System Target File: If you have Embedded Coder, try using "ert.tlc" instead of "grt.tlc" for more streamlined code. You may refer to the below link to know more about the same: https://www.mathworks.com/help/ecoder/index.html#:~:text=Embedded%20Coder%C2%AE%20generates%20readable%2C%20compact%2C%20and%20fast%20C%20and%20C%2B%2B%20code%20for%20embedded%20processors%20used%20in%20mass%20production
  2. Simplify Function Packaging: Set the "Code interface packaging" to "Nonreusable function" to reduce the number of generated files. You can know more about it from the below link: https://www.mathworks.com/help/rtw/ref/codeinterfacepackaging.html
  3. Signal and Memory Management: Disable Signal "storage reuse" for clearer code, and enable "Remove unused functions" to avoid unnecessary code.
  4. Combine Functions: You can enable "Combine output" and "update functions" to minimize function calls in the code.
You may also refer to the below MATLAB Answers post to gain some more insights: https://www.mathworks.com/support/search.html/answers/764006-readability-of-matlab-code.html
  1 件のコメント
Glen Tallarek
Glen Tallarek 2024 年 10 月 29 日
Hi Abhas - Thank you for the information, I will give your suggestions a try!

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

その他の回答 (0 件)

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by