FORMAT Control the Format of Matrix Display

Section: Input/Ouput Functions

Usage

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.

Example

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.3610    0.1437   -0.6212   -0.8556 
   -0.5851   -0.6293   -0.7944    0.7246 
   -0.7003    3.0445   -0.2511   -0.3654 
   -1.5856    0.4217    0.9614    0.5157 

--> b = float(randn(4))

b = 

   -0.6938   -1.7681    0.2468    0.9813 
    0.3994    1.1454   -0.9926    0.2513 
   -0.4021   -0.7800    0.3820   -1.3138 
   -0.1383   -1.4973   -0.3438    0.9952 


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 = 

  -0.36104109917203   0.14371748458334  -0.62119867856148  -0.85561084566703 
  -0.58514130479808  -0.62934886335610  -0.79443760799311   0.72456209775698 
  -0.70030658677887   3.04451182288483  -0.25112914812979  -0.36541385410128 
  -1.58558937953551   0.42165459944770   0.96139968715180   0.51566533614799 

--> b

ans = 

  -0.6937948  -1.7681128   0.2468418   0.9813337 
   0.3994139   1.1454117  -0.9926057   0.2513486 
  -0.4021498  -0.7800179   0.3820494  -1.3138303 
  -0.1382517  -1.4973482  -0.3438159   0.9952367 


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.3610    0.1437   -0.6212   -0.8556 
   -0.5851   -0.6293   -0.7944    0.7246 
   -0.7003    3.0445   -0.2511   -0.3654 
   -1.5856    0.4217    0.9614    0.5157 

--> a*1e-4

ans = 

   1.0e-04 * 

   -0.3610    0.1437   -0.6212   -0.8556 
   -0.5851   -0.6293   -0.7944    0.7246 
   -0.7003    3.0445   -0.2511   -0.3654 
   -1.5856    0.4217    0.9614    0.5157 

--> b*1e4

ans = 

   1.0e+04 * 

   -0.6938   -1.7681    0.2468    0.9813 
    0.3994    1.1454   -0.9926    0.2513 
   -0.4021   -0.7800    0.3820   -1.3138 
   -0.1383   -1.4973   -0.3438    0.9952 

--> b*1e-4

ans = 

   1.0e-04 * 

   -0.6938   -1.7681    0.2468    0.9813 
    0.3994    1.1454   -0.9926    0.2513 
   -0.4021   -0.7800    0.3820   -1.3138 
   -0.1383   -1.4973   -0.3438    0.9952 


Next, we use the exponential formats:

--> format short e
--> a*1e4

ans = 

 -3.6104e+03  1.4372e+03 -6.2120e+03 -8.5561e+03 
 -5.8514e+03 -6.2935e+03 -7.9444e+03  7.2456e+03 
 -7.0031e+03  3.0445e+04 -2.5113e+03 -3.6541e+03 
 -1.5856e+04  4.2165e+03  9.6140e+03  5.1567e+03 

--> a*1e-4

ans = 

 -3.6104e-05  1.4372e-05 -6.2120e-05 -8.5561e-05 
 -5.8514e-05 -6.2935e-05 -7.9444e-05  7.2456e-05 
 -7.0031e-05  3.0445e-04 -2.5113e-05 -3.6541e-05 
 -1.5856e-04  4.2165e-05  9.6140e-05  5.1567e-05 

--> b*1e4

ans = 

 -6.9379e+03 -1.7681e+04  2.4684e+03  9.8133e+03 
  3.9941e+03  1.1454e+04 -9.9261e+03  2.5135e+03 
 -4.0215e+03 -7.8002e+03  3.8205e+03 -1.3138e+04 
 -1.3825e+03 -1.4973e+04 -3.4382e+03  9.9524e+03 

--> b*1e-4

ans = 

 -6.9379e-05 -1.7681e-04  2.4684e-05  9.8133e-05 
  3.9941e-05  1.1454e-04 -9.9261e-05  2.5135e-05 
 -4.0215e-05 -7.8002e-05  3.8205e-05 -1.3138e-04 
 -1.3825e-05 -1.4973e-04 -3.4382e-05  9.9524e-05 


Finally, if we assign the format function to a variable, we can retrieve the current format:

--> format short
--> t = format

t = 

 short


inserted by FC2 system