Main Content

Compose String

Compose output string signal based on specified format and input signals

  • Library:
  • Simulink / String

  • Compose String block

Description

TheCompose Stringblock composes output string signal based on the format specifier listed in theFormatparameter. TheFormatparameter determines the number of input signals. If there are multiple inputs, the block constructs the string by combining these multiple inputs in order, and applying the associated format specifier, one format specifier for each input. Each format specifier starts with a percent sign,%, followed by the conversion character. For example,%fformats the input as a floating point output. To supplement the string output, you can also add a character to the format specification. Use this block to compose and format an output string signal from a multiple inputs.

For example, if theFormatparameter contains"%s is %f", the block expects two inputs, a string signal and a single or double signal. If the first input is the string"Pi"and the second input is a double value3.14, the output is"Pi is 3.14".

When a MinGW®compiler compiles code generated from the block, running the compiled code may produce nonstandard results for floating-point inputs. For example, a numeric input of501.987returns the string"5.019870e+002"instead of the expected string"5.019870e+02".

Ports

Input

expand all

Data for the first part of string, specified as a scalar. TheFormatparameter determines the port label and the format of the input data. For example, if the first item in theFormatparameter is%d, the port label is d.

The data type of the input signal must be compatible with the format specifier in theFormatparameter. For more information, see theFormatparameter.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|Boolean

Data for the second part of string, specified as a scalar. TheFormatparameter determines the port label and the format of the input data. For example, if the first item in theFormatparameter is%f, the port label is f.

The data type of the input signal must be compatible with the format specifier specified in theFormatparameter. For more information, see theFormatparameter.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|Boolean|fixed point|enumerated|bus

Data forNparts of string, specified as a scalar. TheFormatparameter determines the port label and the format of the input data. For example, if the corresponding item in theFormatparameter is%f, the port label is f.

The data type of the input signal must be compatible with the format specifier in theFormatparameter. For more information, see theFormatparameter.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|Boolean|fixed point|enumerated|bus

Output

expand all

Output string composed of inputs, specified as a scalar.

Data Types:string

Parameters

expand all

的格式输入数据,指定为一个标量。

For more information about acceptable format specifiers, see the Algorithms section.

Output data type, specified using the string data type to specify a string with no maximum length.

To specify a string data type with a maximum length, specifystringtype(N). For example,stringtype (31)creates a string data type with a maximum length of 31 characters.

Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set the data type attributes. SeeSpecify Data Types Using Data Type Assistantfor more information.

Block Characteristics

Data Types

double|integer|single|string

Direct Feedthrough

yes

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Algorithms

expand all

A formatting specifier starts with a percent sign,%, and ends with a conversion character. The conversion character is required. Optionally, you can specify identifier, flags, field width, precision, and subtype specifiers between%and the conversion character. (Spaces are invalid between specifiers and are shown here only for readability).

TheCompose Stringblock uses this format specifier prototype:

%[flags][width][.precision][length]specifier

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Introduced in R2018a