1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Terminal Output (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Terminal Output (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Terminal Output (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Basic-Input-and-Output.html" rel="up" title="Basic Input and Output">
<link href="Terminal-Input.html" rel="next" title="Terminal Input">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
pre.format-preformatted {font-family: inherit}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="subsection-level-extent" id="Terminal-Output">
<div class="nav-panel">
<p>
Next: <a href="Terminal-Input.html" accesskey="n" rel="next">Terminal Input</a>, Up: <a href="Basic-Input-and-Output.html" accesskey="u" rel="up">Basic Input and Output</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Terminal-Output-1"><span>14.1.1 Terminal Output<a class="copiable-link" href="#Terminal-Output-1"> ¶</a></span></h4>
<p>Since Octave normally prints the value of an expression as soon as it
has been evaluated, the simplest of all I/O functions is a simple
expression. For example, the following expression will display the
value of ‘<samp class="samp">pi</samp>’
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">pi
-| ans = 3.1416
</pre></div></div>
<p>This works well as long as it is acceptable to have the name of the
variable (or ‘<samp class="samp">ans</samp>’) printed along with the value. To print the
value of a variable without printing its name, use the function
<code class="code">disp</code>.
</p>
<p>The <code class="code">format</code> command offers some control over the way Octave prints
values with <code class="code">disp</code> and through the normal echoing mechanism.
</p>
<a class="anchor" id="XREFdisp"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-disp"><span><strong class="def-name">disp</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-disp"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-disp-1"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">disp</strong> <code class="def-code-arguments">(<var class="var">x</var>)</code><a class="copiable-link" href="#index-disp-1"> ¶</a></span></dt>
<dd><p>Display the value of <var class="var">x</var>.
</p>
<p>For example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">disp ("The value of pi is:"), disp (pi)
-| the value of pi is:
-| 3.1416
</pre></div></div>
<p>Note that the output from <code class="code">disp</code> always ends with a newline.
</p>
<p>If an output value is requested, <code class="code">disp</code> prints nothing and returns the
formatted output in a string.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Simple-File-I_002fO.html#XREFfdisp">fdisp</a>.
</p></dd></dl>
<a class="anchor" id="XREFlist_005fin_005fcolumns"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-list_005fin_005fcolumns"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">list_in_columns</strong> <code class="def-code-arguments">(<var class="var">arg</var>, <var class="var">width</var>, <var class="var">prefix</var>)</code><a class="copiable-link" href="#index-list_005fin_005fcolumns"> ¶</a></span></dt>
<dd><p>Return a string containing the elements of <var class="var">arg</var> listed in columns with
an overall maximum width of <var class="var">width</var> and optional prefix <var class="var">prefix</var>.
</p>
<p>The argument <var class="var">arg</var> must be a cell array of character strings or a
character array.
</p>
<p>If <var class="var">width</var> is not specified or is an empty matrix, or less than or equal
to zero, the width of the terminal screen is used. Newline characters are
used to break the lines in the output string. For example:
</p>
<div class="example smallexample">
<div class="group"><pre class="example-preformatted">list_in_columns ({"abc", "def", "ghijkl", "mnop", "qrs", "tuv"}, 20)
⇒ abc mnop
def qrs
ghijkl tuv
whos ans
⇒
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
ans 1x37 37 char
Total is 37 elements using 37 bytes
</pre></div></div>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFterminal_005fsize">terminal_size</a>.
</p></dd></dl>
<a class="anchor" id="XREFterminal_005fsize"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-terminal_005fsize"><span><code class="def-type">[<var class="var">rows</var>, <var class="var">cols</var>] =</code> <strong class="def-name">terminal_size</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-terminal_005fsize"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-terminal_005fsize-1"><span><strong class="def-name">terminal_size</strong> <code class="def-code-arguments">([<var class="var">rows</var>, <var class="var">cols</var>])</code><a class="copiable-link" href="#index-terminal_005fsize-1"> ¶</a></span></dt>
<dd><p>Query or set the size of the terminal window. If called with no arguments,
return a two-element row vector containing the current size of the terminal
window in characters (rows and columns). If called with a two-element vector
of integer values, set the terminal size and return the previous setting.
Setting the size manually should not be needed when using readline for
command-line editing.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFlist_005fin_005fcolumns">list_in_columns</a>.
</p></dd></dl>
<a class="anchor" id="XREFformat"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-format"><span><strong class="def-name">format</strong><a class="copiable-link" href="#index-format"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-format-1"><span><strong class="def-name">format</strong> <code class="def-code-arguments">options</code><a class="copiable-link" href="#index-format-1"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-format-2"><span><strong class="def-name">format</strong> <code class="def-code-arguments">(<var class="var">options</var>)</code><a class="copiable-link" href="#index-format-2"> ¶</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-format-3"><span><code class="def-type">[<var class="var">format</var>, <var class="var">formatspacing</var>, <var class="var">uppercase</var>] =</code> <strong class="def-name">format</strong><a class="copiable-link" href="#index-format-3"> ¶</a></span></dt>
<dd><p>Reset or specify the format of the output produced by <code class="code">disp</code> and Octave’s
normal echoing mechanism.
</p>
<p>This command only affects the display of numbers, not how they are stored
or computed. To change the internal representation from the default double use
one of the conversion functions such as <code class="code">single</code>, <code class="code">uint8</code>,
<code class="code">int64</code>, etc. Any <code class="code">format</code> options that change the number of
displayed significant digits will also be reflected by the
<code class="code">output_precision</code> function.
</p>
<p>By default, Octave displays 5 significant digits in a human readable form
(option ‘<samp class="samp">short</samp>’, option ‘<samp class="samp">lowercase</samp>’, and option ‘<samp class="samp">loose</samp>’ format
for matrices). If <code class="code">format</code> is invoked without any options, or the option
‘<samp class="samp">default</samp>’ is specified, then this default format is restored.
</p>
<p>Valid format options for floating point numbers are listed in the following
table.
</p>
<dl class="table">
<dt><code class="code">default</code></dt>
<dd><p>Restore the default format state described above.
</p>
</dd>
<dt><code class="code">short</code></dt>
<dd><p>Fixed point format with 5 significant figures (default).
</p>
</dd>
<dt><code class="code">long</code></dt>
<dd><p>Fixed point format with 16 significant figures.
</p>
<p>As with the ‘<samp class="samp">short</samp>’ format, Octave will switch to an exponential ‘<samp class="samp">e</samp>’
format if it is unable to format a matrix properly using the current format.
</p>
</dd>
<dt><code class="code">shorte</code></dt>
<dt><code class="code">longe</code></dt>
<dd><p>Exponential format. The number to be represented is split between a mantissa
and an exponent (power of 10). The mantissa has 5 significant digits in the
short format. In the long format, double values are displayed with 16
significant digits and single values are displayed with 8. For example,
with the ‘<samp class="samp">shorte</samp>’ format, <code class="code">pi</code> is displayed as <code class="code">3.1416e+00</code>.
Optionally, the trailing ‘<samp class="samp">e</samp>’ can be split into a second argument.
</p>
</dd>
<dt><code class="code">shortg</code></dt>
<dt><code class="code">longg</code></dt>
<dd><p>Optimally choose between fixed point and exponential format based on the
magnitude of the number. For example, with the ‘<samp class="samp">shortg</samp>’ format,
<code class="code">pi .^ [2; 4; 8; 16; 32]</code><!-- /@w --> is displayed as
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">ans =
9.8696
97.409
9488.5
9.0032e+07
8.1058e+15
</pre></div></div>
<p>Optionally, the trailing ‘<samp class="samp">g</samp>’ can be split into a second argument.
</p>
</dd>
<dt><code class="code">shorteng</code></dt>
<dt><code class="code">longeng</code></dt>
<dd><p>Identical to ‘<samp class="samp">shorte</samp>’ or ‘<samp class="samp">longe</samp>’ but displays the value using an
engineering format, where the exponent is divisible by 3. For example, with
the ‘<samp class="samp">shorteng</samp>’ format, <code class="code">10 * pi</code> is displayed as <code class="code">31.416e+00</code>.
Optionally, the trailing ‘<samp class="samp">eng</samp>’ can be split into a second argument.
</p>
</dd>
<dt><code class="code">free</code></dt>
<dt><code class="code">none</code></dt>
<dd><p>Print output in free format, without trying to line up columns of matrices on
the decimal point. This is a raw format equivalent to the C++ code
<code class="code">std::cout << <var class="var">variable</var></code>. In general, the result is a presentation
with 6 significant digits where unnecessary precision (such as trailing zeros
for integers) is suppressed. Complex numbers are formatted as numeric pairs
like this <code class="code">(0.60419, 0.60709)</code> instead of like this
<code class="code">0.60419 + 0.60709i</code>.
</p></dd>
</dl>
<p>The following formats affect all numeric output (floating point and integer
types).
</p>
<dl class="table">
<dt><code class="code">"+"</code></dt>
<dt><code class="code">"+"</code> <code class="code">"<var class="var">chars</var>"</code></dt>
<dt><code class="code">plus</code></dt>
<dt><code class="code">plus <var class="var">chars</var></code></dt>
<dd><p>Print a ‘<samp class="samp">+</samp>’ symbol for matrix elements greater than zero, a ‘<samp class="samp">-</samp>’
symbol for elements less than zero, and a space for zero matrix elements. This
format can be useful for examining the sparsity structure of a large matrix.
For very large matrices the function <code class="code">spy</code> which plots the sparsity
pattern will be clearer.
</p>
<p>The optional argument <var class="var">chars</var> specifies a list of 3 characters to use for
printing values greater than zero, less than zero, and equal to zero. For
example, with the format <code class="code">"+" "+-."</code>, the matrix
<code class="code">[1, 0, -1; -1, 0, 1]</code> is displayed as
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">ans =
+.-
-.+
</pre></div></div>
</dd>
</dl>
<dl class="table">
<dt><code class="code">bank</code></dt>
<dd><p>Print variable in a format appropriate for a currency (fixed format with two
digits to the right of the decimal point). Only the real part of a variable is
displayed, as the imaginary part makes no sense for a currency.
</p>
</dd>
<dt><code class="code">bit</code></dt>
<dd><p>Print the bit representation of numbers in memory, always with the
most significant bit first. For example, <code class="code">pi</code> is printed like this:
</p>
<div class="format smallformat">
<pre class="format-preformatted"><code class="code">0 10000000000 1001001000011111101101010100010001000010110100011000</code>
</pre></div>
<p>where spaces have been added for clarity to show the sign bit, the 11-bit
exponent, and the 52-bit mantissa, in that order. Together they represent
<code class="code">pi</code> as an IEEE 754 double precision floating point number in the
normal form. Single precision floating point numbers are analogous.
</p>
</dd>
<dt><code class="code">native-bit</code></dt>
<dd><p>Print the bit representation of numbers as stored in memory. For big-endian
machines, this is identical to the <code class="code">format bit</code> layout seen above.
For little-endian machines, it will print the bytes in the opposite order,
though bits within a byte will still be presented with the most significant
bit on the left.
</p>
<p>For example, the value of <code class="code">pi</code> in this format on x86-64 is:
</p>
<div class="format smallformat">
<pre class="format-preformatted"><code class="code">00011000 00101101 01000100 01010100 11111011 00100001 00001001 01000000</code>
</pre></div>
<p>shown here with spaces added for clarity. Compare with the previous bit string
from <code class="code">format bit</code> to see the grouping into bytes and their ordering.
</p>
</dd>
<dt><code class="code">hex</code></dt>
<dd><p>The same as <code class="code">format bit</code> above, except that bits are grouped four at a
time into hexadecimal digits for brevity. Thus <code class="code">pi</code> is represented as:
</p>
<div class="example">
<pre class="example-preformatted">400921fb54442d18
</pre></div>
</dd>
<dt><code class="code">native-hex</code></dt>
<dd><p>The same as <code class="code">format native-bit</code> above, except that bits are grouped four
at a time into hexadecimal digits for brevity. Thus <code class="code">pi</code> is represented
on an x86-64 as:
</p>
<div class="example">
<pre class="example-preformatted">182d4454fb210940
</pre></div>
</dd>
<dt><code class="code">rat</code></dt>
<dd><p>Print a rational approximation, i.e., values are approximated as the ratio of
small integers. For example, with the ‘<samp class="samp">rat</samp>’ format, <code class="code">pi</code> is
displayed as <code class="code">355/113</code>.
</p></dd>
</dl>
<p>The following two options affect the display of scientific and hex notations.
</p>
<dl class="table">
<dt><code class="code">lowercase (default)</code></dt>
<dd><p>Use a lowercase ‘<samp class="samp">e</samp>’ for the exponent character in scientific notation and
lowercase ‘<samp class="samp">a-f</samp>’ for the hex digits representing 10-15.
</p>
</dd>
<dt><code class="code">uppercase</code></dt>
<dd><p>Use an uppercase ‘<samp class="samp">E</samp>’ for the exponent character in scientific notation and
uppercase ‘<samp class="samp">A-F</samp>’ for the hex digits representing 10-15.
</p></dd>
</dl>
<p>The following two options affect the display of all matrices.
</p>
<dl class="table">
<dt><code class="code">compact</code></dt>
<dd><p>Remove blank lines around column number labels and between matrices producing
more compact output with more data per page.
</p>
</dd>
<dt><code class="code">loose (default)</code></dt>
<dd><p>Insert blank lines above and below column number labels and between matrices to
produce a more readable output with less data per page.
</p></dd>
</dl>
<p>If <code class="code">format</code> is called with multiple competing options, the rightmost one
is used, except for ‘<samp class="samp">default</samp>’ which will override all other options. In
case of an error the format remains unchanged.
</p>
<p>If called with one to three output arguments, and no inputs, return the current
format, format spacing, and uppercase preference. Specifying both outputs and
inputs will produce an error.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Matrices.html#XREFfixed_005fpoint_005fformat">fixed_point_format</a>, <a class="ref" href="Matrices.html#XREFoutput_005fprecision">output_precision</a>, <a class="ref" href="Matrices.html#XREFsplit_005flong_005frows">split_long_rows</a>, <a class="ref" href="Empty-Matrices.html#XREFprint_005fempty_005fdimensions">print_empty_dimensions</a>, <a class="ref" href="Rational-Approximations.html#XREFrats">rats</a>.
</p></dd></dl>
<ul class="mini-toc">
<li><a href="Paging-Screen-Output.html" accesskey="1">Paging Screen Output</a></li>
</ul>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Terminal-Input.html">Terminal Input</a>, Up: <a href="Basic-Input-and-Output.html">Basic Input and Output</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|