Specify String Scalar Inputs at the Command Line - MATLAB & Simulink (original) (raw)
Main Content
You can specify string scalar input types by using the codegen command with -args
at the command line. Alternatively, you can specify input types by using function argument validation in your MATLAB® code, by using the MATLAB Coder™ app, or by using assert statements in your MATLAB code. For an overview of these four methods of input type specification, see Specify Types of Entry-Point Function Inputs.
To define string scalar inputs at the command line, use one of these procedures:
- Provide an Example String Scalar Input
- Provide a String Scalar Type
- Provide a Constant String Scalar Input
- Provide a Variable-Size String Scalar Input
Alternatively, if you have a test file that calls your entry-point function with example inputs, you can determine the input types by usingcoder.getArgTypes
.
Provide an Example String Scalar Input
To provide an example string scalar tocodegen
, use the -args
option:
codegen myFunction -args {"Hello, world"}
Provide a String Scalar Type
To provide a type for a string scalar to codegen
:
- Define a string scalar. For example:
- Create a type from
s
. - Pass the type to
codegen
by using the-args
option.
codegen myFunction -args {t}
Provide a Constant String Scalar Input
To specify that a string scalar input is constant, usecoder.Constant
with the -args
option:
codegen myFunction -args {coder.Constant("Hello, world")}
Provide a Variable-Size String Scalar Input
To specify that a string scalar input has a variable-size:
- Define a string scalar. For example:
- Create a type from
s
. - Assign the
StringLength
property of the type the upper bound of the string length and setVariableStringLength
totrue
. For example, specify that typet
is variable-size with an upper bound of 10.
t.StringLength = 10;
t.VariableStringLength = true;
To specify thatt
is variable-size with no upper bound:
This automatically sets theVariableStringLength
property totrue
. - Pass the type to
codegen
by using the-args
option.
codegen myFunction -args {t}
See Also
coder.Constant | coder.getArgTypes | coder.typeof