Main Content

stringtype

Create string data type

Description

string = stringtype(maximum_length) creates a Simulink® string data type with a maximum length. Alternatively, you can also create string data types using the String Constant, String Concatenate, and Compose String blocks.

stringtype(maximum_length) creates a Simulink string data type with a maximum length that you can type directly on the MATLAB® command line or in the Output data type parameter of the String Constant, String Concatenate, or Compose String block.

Tip

Specifying stringtype(0) creates a string data type with no maximum length. This syntax is the same as specifying string for Simulink block data types.

example

Examples

collapse all

Create a string data type of maximum length 10.

h=stringtype(10)
h = 

  StringType with properties:

    MaximumLength: 10
      Description: ''
        DataScope: 'Auto'
       HeaderFile: ''

Create a string data type that uses symbolic expression for maximum length. For more information about symbolic dimensions, see Implement Symbolic Dimensions for Array Sizes in Generated Code (Simulink Coder).

A = Simulink.Parameter(int32(10));
A.Min = 1;
A.Max = 100;
A.StorageClass = 'Define';
A.CoderInfo.CustomAttributes.HeaderFile = 'symbols.h';
h = stringtype("A")
h = 

  StringType with properties:

    MaximumLength: 'A'
      Description: ''
        DataScope: 'Auto'
       HeaderFile: ''

Input Arguments

collapse all

When the maximum length of the string data type is specified as a scalar, it can take values from 1 to 32766. This value can be an integer, MATLAB variable, or MATLAB expression.

You can also use symbolic expressions for maximum length. (since R2024a)

Data Types: double | string

Output Arguments

collapse all

String object, specified as a scalar.

Version History

Introduced in R2018a

expand all