FreeMat
|
Section: Input/Ouput Functions
FreeMat supports several modes for displaying matrices (either through the disp
function or simply by entering expressions on the command line. There are several options for the format command. The default mode is equivalent to
format short
which generally displays matrices with 4 decimals, and scales matrices if the entries have magnitudes larger than roughly 1e2
or smaller than 1e-2
. For more information you can use
format long
which displays roughly 7 decimals for float
and complex
arrays, and 14 decimals for double
and dcomplex
. You can also use
format short e
to get exponential format with 4 decimals. Matrices are not scaled for exponential formats. Similarly, you can use
format long e
which displays the same decimals as format long
, but in exponential format. You can also use the format
command to retrieve the current format:
s = format
where s
is a string describing the current format.
We start with the short format, and two matrices, one of double precision, and the other of single precision.
--> format short --> a = randn(4) a = -0.3756 0.0920 0.9516 1.8527 0.5078 -0.2088 -0.3120 -0.2380 0.5578 0.7695 0.0226 2.9326 -0.4420 -0.4871 -0.7582 -0.5059 --> b = float(randn(4)) b = 0.2010 0.3416 0.1562 -0.5460 1.2842 -0.3808 -1.2720 -0.3398 -0.7660 -0.6251 2.4811 0.7956 -0.1727 0.8577 1.5701 -1.5048
Note that in the short format, these two matrices are displayed with the same format. In long
format, however, they display differently
--> format long --> a ans = Columns 1 to 3 -0.37559630424227 0.09196341864118 0.95155934364300 0.50776589164635 -0.20877480315311 -0.31198760445638 0.55783547335483 0.76954243414671 0.02264031516947 -0.44202929771190 -0.48708606879623 -0.75822963661106 Columns 4 to 4 1.85265231634028 -0.23799081322695 2.93263318869123 -0.50590405332950 --> b ans = 0.2010476 0.3415550 0.1561587 -0.5460028 1.2841575 -0.3808453 -1.2719837 -0.3397521 -0.7659672 -0.6251388 2.4811494 0.7956446 -0.1726678 0.8576548 1.5701485 -1.5048176
Note also that we we scale the contents of the matrices, FreeMat rescales the entries with a scale premultiplier.
--> format short --> a*1e4 ans = 1.0e+04 * -0.3756 0.0920 0.9516 1.8527 0.5078 -0.2088 -0.3120 -0.2380 0.5578 0.7695 0.0226 2.9326 -0.4420 -0.4871 -0.7582 -0.5059 --> a*1e-4 ans = 1.0e-04 * -0.3756 0.0920 0.9516 1.8527 0.5078 -0.2088 -0.3120 -0.2380 0.5578 0.7695 0.0226 2.9326 -0.4420 -0.4871 -0.7582 -0.5059 --> b*1e4 ans = 1.0e+04 * 0.2010 0.3416 0.1562 -0.5460 1.2842 -0.3808 -1.2720 -0.3398 -0.7660 -0.6251 2.4811 0.7956 -0.1727 0.8577 1.5701 -1.5048 --> b*1e-4 ans = 1.0e-04 * 0.2010 0.3416 0.1562 -0.5460 1.2842 -0.3808 -1.2720 -0.3398 -0.7660 -0.6251 2.4811 0.7956 -0.1727 0.8577 1.5701 -1.5048
Next, we use the exponential formats:
--> format short e --> a*1e4 ans = -3.7560e+03 9.1963e+02 9.5156e+03 1.8527e+04 5.0777e+03 -2.0877e+03 -3.1199e+03 -2.3799e+03 5.5784e+03 7.6954e+03 2.2640e+02 2.9326e+04 -4.4203e+03 -4.8709e+03 -7.5823e+03 -5.0590e+03 --> a*1e-4 ans = -3.7560e-05 9.1963e-06 9.5156e-05 1.8527e-04 5.0777e-05 -2.0877e-05 -3.1199e-05 -2.3799e-05 5.5784e-05 7.6954e-05 2.2640e-06 2.9326e-04 -4.4203e-05 -4.8709e-05 -7.5823e-05 -5.0590e-05 --> b*1e4 ans = 2.0105e+03 3.4156e+03 1.5616e+03 -5.4600e+03 1.2842e+04 -3.8085e+03 -1.2720e+04 -3.3975e+03 -7.6597e+03 -6.2514e+03 2.4811e+04 7.9564e+03 -1.7267e+03 8.5765e+03 1.5701e+04 -1.5048e+04 --> b*1e-4 ans = 2.0105e-05 3.4155e-05 1.5616e-05 -5.4600e-05 1.2842e-04 -3.8085e-05 -1.2720e-04 -3.3975e-05 -7.6597e-05 -6.2514e-05 2.4811e-04 7.9564e-05 -1.7267e-05 8.5765e-05 1.5701e-04 -1.5048e-04
Finally, if we assign the format
function to a variable, we can retrieve the current format:
--> format short --> t = format t = short