String to Single - Convert string signal to single signal - Simulink (original) (raw)
Convert string signal to single signal
Libraries:
Simulink / String
Description
Scan String scans an input string and converts it to signals per the format specified by the Format parameter. The block converts values to their decimal (base 10) representation and outputs the results as numeric or string signals. For example, if the Format parameter is set to"%s is %f."
, the block outputs two parts, a string signal and a single signal. If the input is the string "Pi is 3.14"
, the two outputs are "Pi"
and "3.14"
.
The Scan String, String to Double, and String to Single blocks are identical blocks. When configured for String to Double, the block converts the input string signal to a double numerical output. When configured for String to Single, the block converts the input string signal to a single numerical output.
For code generation, configure models that contain this block for non-finite number support by selecting the > > > check box.
Ports
Input
Input string, specified as a scalar.
Data Types: string
Output
Output data whose format matches specified format, defined as a scalar. Total maximum number of outputs is 128.
If the block cannot match an input string to a format operator specified in Format, it returns a warning and outputs an appropriate value (0
or""
) for each unmatched format operator.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
| enumerated
| bus
Output data whose format matches the %f
format, specified as a scalar. Total maximum number of outputs is 128.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
| enumerated
| bus
Output data whose format matches N
format, specified as a scalar. Total maximum number of outputs is 128.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| Boolean
| fixed point
| enumerated
| bus
Parameters
Format operator for input, specified as a scalar. If the block cannot match the input string with the specified format, it returns0
. The return of 0
differs from the sscanf function return, which is an empty matrix if the function cannot match the input with the specified format.
- For the String to Double block, this parameter has a default value of
%lf
. - For the String to Single block, this parameter has a default value of
%f
.
For more information about acceptable format operators, see the Algorithms section.
Programmatic Use
Block Parameter: Format |
---|
Type: character vector |
Values: '' |
Default: '"%f"' |
Block Characteristics
Data Types | double | integer | single | string |
---|---|---|---|
Direct Feedthrough | yes | ||
Multidimensional Signals | no | ||
Variable-Size Signals | no | ||
Zero-Crossing Detection | no |
Algorithms
The Scan String block uses this format specifier prototype:
%[width][length]specifier
This table lists available conversion specifiers to convert text to numeric outputs. The block converts values to their decimal (base 10) representation.
Output Port Data Type | Conversion Specifier | Description |
---|---|---|
Integer, signed | %d | Base 10 |
Integer, unsigned | %u | Base 10 |
Floating-point number | %f, %e, or%g | Floating-point values. Input fields can containNaN (case sensitive). Input fields that represents floating-point numbers can include leading+ or - symbols and exponential notation using e orE. The conversion specifiers%f, %e, and%g all treat input fields the same way. |
This table lists available conversion specifiers to convert text so that the output is a character array.
Character Field Type | Conversion Specifier | Description |
---|---|---|
String scalar | %s | Read the text until the block encounters white space. |
%c | Read any single character, including white space. To read multiple characters at a time, specify field width. For example, %10c reads 10 characters at a time. | |
Pattern-matching | %[...] | Read only characters in the brackets up to the first nonmatching character or white space.Example:%[mus] reads'summer' as'summ'. |
%[^...] | Read any characters not in the brackets up to the first matching character or white space.Example:%[^m] reads'summer' as'su'. |
- Field Width — To specify the maximum number of digits or text characters to read at a time, insert a number after the percent character. For example,
%10s
reads up to 10 characters at a time, including white space.%4f
reads up to four digits at a time, including the decimal point. - Literal Text to Ignore — This block must match the specified text immediately before or after the conversion specifier.
Example:Hell%s
reads"Hello!"
as"o!"
.
The Scan String block supports the h
andl
length subspecifiers. These specifiers can change according to the > > settings.
Length | i | u | f e g | s c |
---|---|---|---|---|
No length specifier | int | unsigned int | single | string |
h | short | unsigned short | — | — |
l | long | unsigned long | double | — |
- Target
int
,long
,short
type sizes are controlled by settings in the > pane. For example, if the targetint
is 32 bits and the specifier is%u
, then the expected input type will beuint32
. For this example, the Scan String block requires that the output type be exactlyint32
. It cannot be any other data type.
Extended Capabilities
Version History
Introduced in R2018a