compose
Format data into multiple strings
Description
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
Ahas multiple rows, thencomposereturnsstras a string array or cell array with the same number of rows.composerepeatsformatSpecin each row ofstr, with formatted values from the corresponding row ofA.If the number of columns in
Aexceeds the number of operators informatSpec, thencomposerepeatsformatSpecas an additional column ofstr. The extra columns ofAcontribute formatted values to the new column instr.If the number of columns in
Ais less than the number of operators informatSpec, thencomposedoes not format values using those operators. Instead,composeputs unchanged formatting operators instr. However,composetranslates 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
txtdoes not contain formatting operators, thencomposetranslates all escape-character sequences. It leaves all other characters unchanged.If
txtcontains formatting operators, thencomposetranslates all escape-character sequences except for\\and%%. It leaves all other characters, including the formatting operators, unchanged.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced in R2016b