Main Content

coder.StringType class

Package: coder
Superclasses: coder.Type

Represent set of MATLAB strings acceptable for input specification

Description

Objects of coder.StringType specify a set of string inputs the generated code accepts. Use objects of this class only with the -args option of the codegen command to specify input types to the code generator. Do not pass as an input to a generated MEX function.

Creation

Description

example

t = coder.typeof(sInput) creates a coder.StringType object that has the same properties as the string input sInput.

example

t = coder.newtype('string') creates a coder.StringType object for a string scalar. A string scalar contains one piece of text represented as a character vector. To specify the length of the character vector and whether the length has variable-size, set the StringLength property to the required size and set VariableStringLength to true. For example, setting t.StringLength = 10 and t.VariableStringLength = true specify that the string scalar has variable-size with an upper bound of 10.

Input Arguments

expand all

String input, specified as a constant string scalar or string variable.

Properties

expand all

Name of class, returned as a character vector.

Attributes:

GetAccess
public
SetAccess
private

Maximum length of the string scalar, specified as an integer.

Setting this property to Inf automatically sets VariableStringLength to true.

Attributes:

GetAccess
public
SetAccess
public

Option to specify whether the string length of the string type object has fixed or variable size. A value of true indicates that the string length has variable size. A value of false indicates that the string length has fixed size.

Attributes:

GetAccess
public
SetAccess
public

Examples

collapse all

This example shows how to create a type object for a string scalar. Use this type object to specify a string scalar input type to the code generator.

Create String Type Object by Using Example String

Create an example string scalar.

stringEx = "Hello, World";

Pass this example string to coder.typeof to create a coder.StringType object.

typeObj = coder.typeof(stringEx)
typeObj = 
coder.StringType
   1×1 string
      StringLength: 12
      VariableStringLength: false

    Edit Type Object

To specify the upper bound of the string length, set the StringLength property to the desired length.

typeObj.StringLength = 20;

To specify a variable string length, set VariableStringLength to true.

typeObj.VariableStringLength = true
typeObj = 
coder.StringType
   1×1 string
      StringLength: 20
      VariableStringLength: true

    Edit Type Object

You can set StringLength to Inf to make the string length unbounded and automatically sets VariableStringLength to true.

typeObj.StringLength = Inf
typeObj = 
coder.StringType
   1×1 string
      StringLength: inf
      VariableStringLength: true

    Edit Type Object

Create String Type Object by Using coder.newtype

To create a string type object by using coder.newtype, use the following command.

typeObj = coder.newtype('string')
typeObj = 
coder.StringType
   1×1 string
      StringLength: 0
      VariableStringLength: false

    Edit Type Object

To specify the string length of the type object, set the StringLength property to the desired length.

typeObj.StringLength = 20;

To specify a variable string length, set VariableStringLength to true.

typeObj.VariableStringLength = true
typeObj = 
coder.StringType
   1×1 string
      StringLength: 20
      VariableStringLength: true

    Edit Type Object

Version History

Introduced in R2022b