formattedDisplayText
Description
returns the Command Window display output of str
= formattedDisplayText(X
)X
as a string. The string
contains disp(X)
.
specifies formatting options for the string using one or more str
= formattedDisplayText(X
,Name,Value
)Name,Value
arguments.
Examples
Capture Matrices as Strings
Create a 3-by-3 diagonal matrix.
I = diag([1 1 1]);
Use formattedDisplayText
to capture the matrix as a string.
strI = formattedDisplayText(I)
strI = " 1 0 0 0 1 0 0 0 1 "
You can also use expressions as inputs.
strIplus = formattedDisplayText(2*I + ones(3))
strIplus = " 3 1 1 1 3 1 1 1 3 "
Format Logical Values and Capture Struct as String
Create a struct that contains information about a UI element.
S = struct('Type','Button','Size', 45,'Enabled',false)
S = struct with fields:
Type: 'Button'
Size: 45
Enabled: 0
Use formattedDisplayText
with the UseTrueFalseforLogical
name-value argument to capture the struct as a string with logical values displayed as "true" or "false".
strS = formattedDisplayText(S,'UseTrueFalseForLogical',true)
strS = " Type: 'Button' Size: 45 Enabled: false "
Format Table and Capture as String
Create a table with customer names, account balances, and amounts of recent deposits.
Customer = ["Rivera";"Park";"Gupta"]; Balance = [5670;868.54;3015]; LastDeposit = [325.10;35.20;70]; T = table(Customer,Balance,LastDeposit)
T = 3×3 table Customer Balance LastDeposit ________ _______ ___________ "Rivera" 5670 325.1 "Park" 868.54 35.2 "Gupta" 3015 70
Capture the table as a string. Use name-value arguments to set the numeric format to bank style, suppress the boldface markup of the column headings, and remove an extra blank line with compact line spacing.
strT = formattedDisplayText(T,'NumericFormat','bank',... 'SuppressMarkup',true,'LineSpacing','compact')
strT = " Customer Balance LastDeposit ________ _______ ___________ "Rivera" 5670.00 325.10 "Park" 868.54 35.20 "Gupta" 3015.00 70.00 "
Input Arguments
X
— Expression to return as string
array
Input array.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'NumericFormat','shortE'
NumericFormat
— Format for numeric values
current display format (default) | 'short'
| 'long'
| 'shortE'
| 'longE'
| ...
Format for numeric values, specified as one of the formats in the table:
Style | Result | Example |
---|---|---|
| Short, fixed-decimal format with 4 digits after the decimal point. | 3.1416 |
| Long, fixed-decimal format with 15 digits after the decimal point
for | 3.141592653589793 |
| Short scientific notation with 4 digits after the decimal point. | 3.1416e+00 |
| Long scientific notation with 15 digits after the decimal point for
| 3.141592653589793e+00 |
| Short, fixed-decimal format or scientific notation, whichever is more compact, with a total of 5 digits. | 3.1416 |
| Long, fixed-decimal format or scientific notation, whichever is
more compact, with a total of 15 digits for | 3.14159265358979 |
| Short engineering notation (exponent is a multiple of 3) with 4 digits after the decimal point. | 3.1416e+000 |
| Long engineering notation (exponent is a multiple of 3) with 15 significant digits. | 3.14159265358979e+000 |
| Positive/Negative format with | + |
| Currency format with 2 digits after the decimal point. | 3.14 |
| Hexadecimal representation of a binary double-precision number. | 400921fb54442d18 |
| Ratio of small integers. | 355/113 |
LineSpacing
— Format for line spacing
current display format (default) | 'loose'
| 'compact'
Format for line spacing, specified as 'loose'
or
'compact'
:
Style | Result | Example |
---|---|---|
| Suppress excess blank lines to show more output on a single screen. | theta = pi/2 |
| Add blank lines to make output more readable. | theta = pi/2 |
SuppressMarkup
— Status of display markup
false
(default) | true
Status of display markup, specified as false
or
true
. When the argument is set to false
, the
output appears exactly as it would in the Command Window, including documentation
hyperlinks and boldface on table headers, for example. When the argument is set to
true
, the output does not show markup, such as hyperlinks and
boldface.
UseTrueFalseForLogical
— Logical value display preference
false
(default) | true
Logical value display preference, specified as false
or
true
. When the argument is set to false
,
logical values appear as 1
s and 0
s. When the
argument is set to true
, logical values appear as the words
"true
" and "false
".
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)