FUNCTION REFERENCE

sprintf

Format data into text.

Format data into text.

Syntax

s = sprintf(format)

Syntax

s = sprintf(format, A, ...)

Returns a character row. format holds plain text and conversions such as %d, %i, %f, %e, %g, %s, %c, %x, %o and %%. Escapes such as \n and \t are converted. All values of all arguments are used in column order. If there are more values than conversions, the format is used again. Text arguments are used as one value for %s and as character codes for %d.

Example

sprintf('%d items, %.2f total', 3, 4.5)   % '3 items, 4.50 total'

A scalar string format returns a string scalar.

Example

sprintf("value=%d", 3)

Differences from MATLAB: cell array arguments and file ids are not supported; use compose for element-wise formatting of string arrays.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.