How can I configure string length in generated Simulink code?

6 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 18 Jan 2024
Modifié(e) : MathWorks Support Team le 29 Fév 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:

Plus de réponses (0)

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by