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

조회 수: 2 (최근 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.

답변 (1개)

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!

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

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by