File: io_format.html

package info (click to toggle)
freemat 4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 174,756 kB
  • ctags: 67,023
  • sloc: cpp: 351,059; ansic: 255,892; sh: 40,590; makefile: 4,387; perl: 4,058; asm: 3,313; pascal: 2,718; fortran: 1,722; ada: 1,681; ml: 1,360; cs: 879; csh: 795; python: 430; sed: 162; lisp: 160; awk: 5
file content (183 lines) | stat: -rw-r--r-- 4,843 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
<TITLE>FORMAT Control the Format of Matrix Display
</TITLE>
</HEAD>
<BODY>
<H2>FORMAT Control the Format of Matrix Display
</H2>
<P>
Section: <A HREF=sec_io.html> Input/Ouput Functions </A>
<H3>Usage</H3>
FreeMat supports several modes for displaying matrices (either through the
<code>disp</code> function or simply by entering expressions on the command line.  
There are several options for the format command.  The default mode is equivalent
to
<PRE>
   format short
</PRE>
<P>
which generally displays matrices with 4 decimals, and scales matrices if the entries
have magnitudes larger than roughly <code>1e2</code> or smaller than <code>1e-2</code>.   For more 
information you can use 
<PRE>
   format long
</PRE>
<P>
which displays roughly 7 decimals for <code>float</code> and <code>complex</code> arrays, and 14 decimals
for <code>double</code> and <code>dcomplex</code>.  You can also use
<PRE>
   format short e
</PRE>
<P>
to get exponential format with 4 decimals.  Matrices are not scaled for exponential 
formats.  Similarly, you can use
<PRE>
   format long e
</PRE>
<P>
which displays the same decimals as <code>format long</code>, but in exponential format.
You can also use the <code>format</code> command to retrieve the current format:
<PRE>
   s = format
</PRE>
<P>
where <code>s</code> is a string describing the current format.
<H3>Example</H3>
We start with the short format, and two matrices, one of double precision, and the
other of single precision.
<PRE>
--&gt; format short
--&gt; a = randn(4)

a = 
    1.9819   -2.4403    0.3082   -0.8708 
    0.3885    0.6777   -2.1203   -0.6899 
   -0.8923   -1.0126   -1.1448   -0.3336 
   -0.5528   -0.2117   -0.6066    0.1530 

--&gt; b = float(randn(4))

b = 
    1.6282   -0.9987   -0.0002    0.7346 
   -0.1461   -0.4450    0.3260    0.0591 
   -0.1927   -0.2583   -0.3209   -1.7827 
   -0.4694   -0.2961   -0.3487   -0.1476 
</PRE>
<P>
Note that in the short format, these two matrices are displayed with the same format.
In <code>long</code> format, however, they display differently
<PRE>
--&gt; format long
--&gt; a

ans = 
   1.98194242245660  -2.44033999910309   0.30822105452542  -0.87083520854217 
   0.38848412098646   0.67772654122050  -2.12029702950896  -0.68985792035578 
  -0.89231827506021  -1.01256221976480  -1.14477420632547  -0.33359041318909 
  -0.55283586680694  -0.21170713821002  -0.60660544623052   0.15300924745427 

--&gt; b

ans = 
   1.6282195  -0.9986902  -0.0002282   0.7346091 
  -0.1460750  -0.4449911   0.3259999   0.0591399 
  -0.1926918  -0.2583237  -0.3208777  -1.7827009 
  -0.4693597  -0.2961315  -0.3487136  -0.1476461 
</PRE>
<P>
Note also that we we scale the contents of the matrices, FreeMat rescales the entries
with a scale premultiplier.
<PRE>
--&gt; format short
--&gt; a*1e4

ans = 

   1.0e+04 * 
    1.9819   -2.4403    0.3082   -0.8708 
    0.3885    0.6777   -2.1203   -0.6899 
   -0.8923   -1.0126   -1.1448   -0.3336 
   -0.5528   -0.2117   -0.6066    0.1530 

--&gt; a*1e-4

ans = 

   1.0e-04 * 
    1.9819   -2.4403    0.3082   -0.8708 
    0.3885    0.6777   -2.1203   -0.6899 
   -0.8923   -1.0126   -1.1448   -0.3336 
   -0.5528   -0.2117   -0.6066    0.1530 

--&gt; b*1e4

ans = 

   1.0e+04 * 
    1.6282   -0.9987   -0.0002    0.7346 
   -0.1461   -0.4450    0.3260    0.0591 
   -0.1927   -0.2583   -0.3209   -1.7827 
   -0.4694   -0.2961   -0.3487   -0.1476 

--&gt; b*1e-4

ans = 

   1.0e-04 * 
    1.6282   -0.9987   -0.0002    0.7346 
   -0.1461   -0.4450    0.3260    0.0591 
   -0.1927   -0.2583   -0.3209   -1.7827 
   -0.4694   -0.2961   -0.3487   -0.1476 
</PRE>
<P>
Next, we use the exponential formats:
<PRE>
--&gt; format short e
--&gt; a*1e4

ans = 
  1.9819e+04 -2.4403e+04  3.0822e+03 -8.7084e+03 
  3.8848e+03  6.7773e+03 -2.1203e+04 -6.8986e+03 
 -8.9232e+03 -1.0126e+04 -1.1448e+04 -3.3359e+03 
 -5.5284e+03 -2.1171e+03 -6.0661e+03  1.5301e+03 

--&gt; a*1e-4

ans = 
  1.9819e-04 -2.4403e-04  3.0822e-05 -8.7084e-05 
  3.8848e-05  6.7773e-05 -2.1203e-04 -6.8986e-05 
 -8.9232e-05 -1.0126e-04 -1.1448e-04 -3.3359e-05 
 -5.5284e-05 -2.1171e-05 -6.0661e-05  1.5301e-05 

--&gt; b*1e4

ans = 
  1.6282e+04 -9.9869e+03 -2.2825e+00  7.3461e+03 
 -1.4608e+03 -4.4499e+03  3.2600e+03  5.9140e+02 
 -1.9269e+03 -2.5832e+03 -3.2088e+03 -1.7827e+04 
 -4.6936e+03 -2.9613e+03 -3.4871e+03 -1.4765e+03 

--&gt; b*1e-4

ans = 
  1.6282e-04 -9.9869e-05 -2.2825e-08  7.3461e-05 
 -1.4608e-05 -4.4499e-05  3.2600e-05  5.9140e-06 
 -1.9269e-05 -2.5832e-05 -3.2088e-05 -1.7827e-04 
 -4.6936e-05 -2.9613e-05 -3.4871e-05 -1.4765e-05 
</PRE>
<P>
Finally, if we assign the <code>format</code> function to a variable, we can retrieve the 
current format:
<PRE>
--&gt; format short
--&gt; t = format

t = 
short
</PRE>
<P>
</BODY>
</HTML>