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
回答(1 个)
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:
- Open the "Model Settings" from the Modeling toolstrip.
- Navigate to Diagnostics > Data Validity.
- 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.
- 'Detect loss of tunability’: https://www.mathworks.com/help/releases/R2021b/simulink/gui/detect-loss-of-tunability.html
- ‘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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!