How can I configure string length in generated Simulink code?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 14 May 2020
Edited: MathWorks Support Team
on 29 Feb 2024
I am attempting to generated code for a Simulink model that contains a "String Constant" block which outputs a "string" type. I noticed that in the generated code, the length of the character array for the "String Constant" defaults to 256. How can I configure this to a custom value?
Accepted Answer
MathWorks Support Team
on 18 Jan 2024
Edited: MathWorks Support Team
on 29 Feb 2024
There are two different ways to configure the generated code in this way. The first is block-specific, while the second is a model-wide configuration.
For the block-specific solution, please change the "Output data type" parameter of the "String Constant" block. Instead of using "string", you should be able to change it to "stringtype(n)" where "n" is the maximum length of the string.
For more information on "Simulink Strings", please run the below command in the MATLAB R2018b command window to get the release specific documentation:
web(fullfile(docroot, 'simulink/ug/simulink-strings.html'))
Further, for the model-wide solution, please configure the buffer size of dynamically-sized strings. This can be done by navigating to Model Configuration Parameters > Code Generation > Interface > Advanced Parameters, and changing the "Buffer size of dynamically-sized string (bytes)" parameter. Please run the below command in the MATLAB R2018b command window to get the release specific documentation that discusses more about the "Buffer size of dynamically-sized string (bytes)":
web(fullfile(docroot, 'rtw/ref/buffer-size-of-dynamically-sized-string-bytes.html'))
Please follow the below link to search for the required information regarding the current release:
0 Comments
More Answers (0)
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware 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!