Main Content

fprintf

Displays variable text centered on masked subsystem icon

    Description

    fprintf(t) displays formatted text centered on the icon.

    example

    fprintf(formatspec,var) formats var as specified in formatspec.

    example

    Examples

    collapse all

    Display the text Hello on the icon.

    fprintf('Hello');

    Convert the character a to an integer 97 and display it on the block icon.

    myvar = 'a'
    fprintf('hello = %d',myvar);
    

    format spec

    Input Arguments

    collapse all

    Text that appears on the block is specified as a string or a character vector.

    Data Types: char | string

    Conversion character for the variable is specified.

    Formatting Operator

    A formatting operator starts with a percent sign, %, and ends with a conversion character. It is mandatory to specify the conversion character. Optionally, you can specify identifier, flags, field width, precision, and subtype operators between % and the conversion character. Spaces are invalid between operators and are shown here only for readability.

    Conversion Character

    This table shows conversion characters to format numeric and character data as text.

    Value TypeConversionDetails

    Integer, signed

    %d or %i

    Base 10

    Integer, unsigned

    %u

    Base 10

    %o

    Base 8 (octal)

    %x

    Base 16 (hexadecimal), lowercase letters af

    %X

    Same as %x, uppercase letters AF

    Floating-point number

    %f

    Fixed-point notation (Use a precision operator to specify the number of digits after the decimal point.)

    %e

    Exponential notation, such as 3.141593e+00 (Use a precision operator to specify the number of digits after the decimal point.)

    %E

    Same as %e, but uppercase, such as 3.141593E+00 (Use a precision operator to specify the number of digits after the decimal point.)

    %g

    The more compact of %e or %f, with no trailing zeros (Use a precision operator to specify the number of significant digits.)

    %G

    The more compact of %E or %f, with no trailing zeros (Use a precision operator to specify the number of significant digits.)

    Characters or strings

    %c

    Single character

    %s

    Character vector or string array. The type of the output text is the same as the type of formatSpec.

    Data Types: char | string

    The variable is formatted as per the formatting character specified in formatspec.

    Note

    While this fprintf function is identical in name to its corresponding MATLAB® function, it provides only the functionality described on this page.

    Version History

    Introduced before R2006a

    See Also

    | |