You can define string scalar inputs at the command line or in the
MATLAB®
Coder™ app. Programmatic specification of string scalar input types by using
preconditioning (assert
statements) is not supported.
To define string scalar inputs at the command line, use one of these procedures:
Alternatively, if you have a test file that calls your entry-point function with
example inputs, you can determine the input types by using
coder.getArgTypes
.
To provide an example string scalar to
codegen
, use the -args
option:
codegen myFunction -args {"Hello, world"}
To provide a type for a string scalar to codegen
:
Define a string scalar. For example:
s = "mystring";
Create a type from
s
.
t = coder.typeof(s);
Pass the type to codegen
by using the
-args
option.
codegen myFunction -args {t}
To specify that a string scalar input is constant, use
coder.Constant
with the -args
option:
codegen myFunction -args {coder.Constant("Hello, world")}
To specify that a string scalar input has a variable-size:
Define a string scalar. For example:
s = "mystring";
Create a type from
s
.
t = coder.typeof(s);
Assign the Value
property of the type to a type
for a variable-size character vector that has the upper bound that
you want. For example, specify that type t
is
variable-size with an upper bound of
10.
t.Properties.Value = coder.typeof('a',[1 10], [0 1]);
To specify that t
is variable-size with
no upper
bound:
t.Properties.Value = coder.typeof('a',[1 inf]);
Pass the type to codegen
by using the
-args
option.
codegen myFunction -args {t}
To define string scalar inputs in the app, use one of these procedures:
coder.Constant
| coder.getArgTypes
| coder.typeof