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

2 次查看(过去 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