How to create an all zero array whose dimensions are defined by the Simulink parameters in the data dictionary?

3 次查看(过去 30 天)
Hello everyone,
I am learning to use Simulink to build some software functions, and I have used the data dictionary to manage my general macro definitions.
I have defined a Simulink parameter N in the data dictionary, and now I want to create an all zero array of N and generate C code using the embedded Coder tools.
My current method is to use the constant module, and also use "=zeros (1, N)" in the data dictionary to define a simulink parameter A, and call this parameter in the constant module.
but I am prompted with the following error message when generating code. Is there any good way to solve it?
The error message as follow:
Unable to preserve expression 'zeros(1,N)', contained in the 'Value' property of Simulink.Parameter object 'A', in the generated code because the expression or its value is not supported.
Thanks
  7 个评论

请先登录,再进行评论。

回答(1 个)

Sandeep Mishra
Sandeep Mishra 2024-9-6
Hi,
It appears that you are attempting to generate C code from the 'test.slx' Simulink file in MATLAB R2021b and you are encountering an error. To address this issue, you can adjust the Model Configuration Parameters to disable the Data Validity error check for "loss of tunability" (refer to the attached 'Screenshot_Model_Settings.png') .
Following are the steps to change the setting:
  1. Open the "Model Settings" from the Modeling toolstrip.
  2. Navigate to Diagnostics > Data Validity.
  3. In the parameters section, change the setting for "loss of tunability" from "error" to either "warning" or "none.".
Following these steps should resolve the error, allowing you to generate the C file using Embedded Coder.
To ensure the ‘N’ variable is included in the generated C file, you should add additional blocks to the Simulink model (refer to the attached 'test.slx' file) and then proceed with generating the C code (refer to the attached 'Screenshot_code_generated.png' file).
Please refer to the below documentation for more information.
  1. 'Detect loss of tunability’: https://www.mathworks.com/help/releases/R2021b/simulink/gui/detect-loss-of-tunability.html
  2. ‘Limitations for Block Parameter Tunability in Generated Code’: https://www.mathworks.com/help/releases/R2021b/rtw/ug/limitations-for-block-parameter-tunability-in-the-generated-code.html
I hope this helps.
  1 个评论
鑫鹏
鑫鹏 2024-9-7
Thank you for your guidance, it has resolved my issue of constantly reporting errors. But I found that there seems to be no zero assignment operation for the A array I created in the generated C code. Do I need to create an additional loop assignment module to initialize the value of A? I searched the help documentation and it seems that the zeros function supports code generation. This is the place that confuses me.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by