How to create an all zero array whose dimensions are defined by the Simulink parameters in the data dictionary?
Show older comments
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 Comments
Sandeep Mishra
on 5 Sep 2024
I tried to recreate the error using the setup shown in the attached screenshot, but I wasn't able to reproduce the error.
Could you please provide more details about the model and its settings?
鑫鹏
on 6 Sep 2024
Sandeep Mishra
on 6 Sep 2024
In which version of MATLAB are you encountering the error?
I tried the attached simulink file and again was not able to reproduce any error in R2021b, Please check the attached screenshot.
For troubleshooting can you please check your base workspace for any conflicting variable names and If that doesn't work then please share the data dictionary file for better analysis.
Sandeep Mishra
on 6 Sep 2024
Which operating system is being used to generate the .c code from the attached model?
鑫鹏
on 6 Sep 2024
鑫鹏
on 6 Sep 2024
Answers (1)
Sandeep Mishra
on 6 Sep 2024
0 votes
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.
Categories
Find more on Code Interface Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!