Note: This page has been translated by MathWorks. Please click here

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Convert data into formatted string array

`str = compose(formatSpec,A)`

`str = compose(formatSpec,A1,...,AN)`

`str = compose(txt)`

formats data values from the input array, `str`

= compose(`formatSpec`

,`A`

)`A`

, using formatting operators
specified by `formatSpec`

and returns the resulting text in
`str`

. The `compose`

function formats values from
`A`

in column order. If `formatSpec`

is a string array, then
so is the output array `str`

. Otherwise, `str`

is a cell array
of character vectors.

`compose`

also translates the escape-character
sequences in `formatSpec`

. Escape-character sequences
represent nonprinting characters or specify actions such as newlines
or tabs.

The `compose`

function can return multiple
pieces of formatted text as a string array or a cell array of character
vectors, unlike `sprintf`

. The `sprintf`

function
returns only a string scalar or a character vector.

If

`A`

has multiple rows, then`compose`

returns`str`

as a string array or cell array with the same number of rows.`compose`

repeats`formatSpec`

in each row of`str`

, with formatted values from the corresponding row of`A`

.If the number of columns in

`A`

exceeds the number of operators in`formatSpec`

, then`compose`

repeats`formatSpec`

as an additional column of`str`

. The extra columns of`A`

contribute formatted values to the new column in`str`

.If the number of columns in

`A`

is less than the number of operators in`formatSpec`

, then`compose`

does not format values using those operators. Instead,`compose`

puts unchanged formatting operators in`str`

. However,`compose`

translates all escape-character sequences except for`\\`

and`%%`

.

formats
data values from multiple input arrays and concatenates all the formatted
values. When `str`

= compose(`formatSpec`

,A1,...,AN)`compose`

uses formatting operators
from `formatSpec`

to convert data from an input array,
then those formatting operators become unavailable to the following
input arrays.

For example, if `formatSpec`

is ```
"%f
%f %d %s"
```

and `A1`

has two columns, then
the operators `"%f %f"`

are applied to the values
in `A1`

only. They cannot be applied to `A2`

or
any other input array. `compose`

applies the remaining
operators, `"%d %s"`

, to `A2,...,AN`

.

If the number of columns in the last input array, `AN`

,
exceeds the number of remaining operators, then `compose`

adds
an additional column to `str`

, as described in the
previous syntax. If the number of columns in `AN`

is
less than the number of remaining operators, then `compose`

puts
the last unchanged operators in `str`

.

translates
escape-character sequences in `str`

= compose(`txt`

)`txt`

.

If

`txt`

does not contain formatting operators, then`compose`

translates all escape-character sequences. It leaves all other characters unchanged.If

`txt`

contains formatting operators, then`compose`

translates all escape-character sequences except for`\\`

and`%%`

. It leaves all other characters, including the formatting operators, unchanged.

Was this topic helpful?