Code Generation for Strings
Code generation supports 1-by-1 MATLAB® string arrays. Code generation does not support string arrays that have more than one element.
A 1-by-1 string array, called a string scalar, contains one
piece of text, represented as a 1-by-n character vector. An example of a string scalar
"Hello, world". For more information about strings, see Text in String and Character Arrays.
For string scalars, code generation does not support:
Indexing with curly braces
Defining input types programmatically by using preconditioning with
assertstatements, when generating code by using the
fiaccel(Fixed-Point Designer) command, or the MATLAB Coder™ app
Their use as Simulink® signals, parameters, or data store memory
For code generation, limitations that apply to classes apply to strings. See MATLAB Classes Definition for Code Generation.
Differences Between Generated Code and MATLAB Code
Converting a string that contains multiple unary operators to
doublecan produce different results between MATLAB and the generated code. Consider this function:
function out = foo(op) out = double(op + 1); end
For an input value
"--", the function converts the string
double. In MATLAB, the answer is
NaN. In the generated code, the answer is
Double conversion for a string with misplaced commas (commas that are not used as thousands separators) can produce different results from MATLAB.