formattedDisplayText
Returns, as a string, the text that displaying a value would print.
Category: Data Import and Analysis > Data Import and Export
Syntax
str = formattedDisplayText(X)
Captures the display of X.
str = formattedDisplayText(X, Name, Value)
Controls the format with options such as 'NumericFormat' and 'LineSpacing'.
Description
The result is exactly what the command window would show for the value, but kept as data. It is useful for building log messages, writing results to a file, or testing the look of a display without the value being echoed. The 'NumericFormat' option acts like format for this single call only.
Input arguments
X- Any value.
'NumericFormat'- Display format such as
'short'or'long'. 'LineSpacing''loose'or'compact'.
Output arguments
str- String scalar with the displayed text, line breaks included.
Example
Capture a display
s = formattedDisplayText([1 2; 3 4]);
class(s)
fprintf('%s', s)
formattedDisplayText(pi, 'NumericFormat', 'long')
Output
ans = 'string'
1 2
3 4
ans = " 3.141592653589793
"