What principles does the accumulator for storing data (output or intermediate) follow after converting the model into C code using a C coder?

조회 수: 3 (최근 30일)
For example, is the upper limit of i in the for loop automatically generated based on factors such as the size of the data or something else?I would like to interrupt the process of generating data into smaller segments as per my request, but I don't know how to handle these data or intermediate quantities because I am concerned that interrupting this process directly may lead to uncontrollable issues such as data leakage or data coverage。

채택된 답변

Abhas
Abhas 2024년 8월 5일
Hi Peter,
When generating C code for Simulink models, the principles for storing data in accumulators generally follow these guidelines:
  1. Fixed Size Inputs: Initially, you generate C code that can accept only inputs of a fixed preassigned size.
  2. Variable Size Inputs: You can also generate C code that can accept inputs of many different sizes.
  3. Array Size Assertions: Asserting the maximum size of arrays is a recommended practice for generating efficient C code. For instance, use assert(N<25); to limit the size of an array.
  4. Passing by Reference: In C, arrays are always passed by reference, which means the original data can be modified by the called function.
To handle the process of generating data into smaller segments in Simulink, you can utilize the "For Each Subsystem" block. This block allows you to partition your data and process each segment individually. Here’s a sample approach to achieve the same:
  1. Add a "For Each Subsystem" block to your model.
  2. Configure the "Partition dimension" and "Partition width" to segment the data.
  3. Inside the "For Each Subsystem", add and connect the processing blocks (e.g., Gain, Sum).
  4. Optionally, add "Data Store Memory" for data handling.
  5. Use "Data Store Read" and "Data Store Write" blocks to manage data within the For Each Subsystem.
You may refer to the following MathWorks documentation links to have a better understanding on generating data into smaller segments:
  1. For Each Subsystem: https://www.mathworks.com/help/releases/R2020b/simulink/slref/foreachsubsystem.html
  2. Data Store Memory: https://www.mathworks.com/help/releases/R2020b/simulink/slref/datastorememory.html
  3. Data Store Read: https://www.mathworks.com/help/releases/R2020b/simulink/slref/datastoreread.html
  4. Data Store Write: https://www.mathworks.com/help/releases/R2020b/simulink/slref/datastorewrite.html
  댓글 수: 1
peter
peter 2024년 8월 6일
@AbhasThank you very much for your suggestions and examples. You explained them very clearly. I will carefully read these documents and immediately start practicing.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by