File: io_format.html

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (211 lines) | stat: -rw-r--r-- 7,553 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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FreeMat: FORMAT Control the Format of Matrix Display</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">FreeMat
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('io_format.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">FORMAT Control the Format of Matrix Display </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Section: <a class="el" href="sec_io.html">Input/Ouput Functions</a> </p>
<h1><a class="anchor" id="Usage"></a>
Usage</h1>
<p>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 </p>
<pre class="fragment">   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 </p>
<pre class="fragment">   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 </p>
<pre class="fragment">   format short e
</pre><p> to get exponential format with 4 decimals. Matrices are not scaled for exponential formats. Similarly, you can use </p>
<pre class="fragment">   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: </p>
<pre class="fragment">   s = format
</pre><p> where <code>s</code> is a string describing the current format. </p>
<h1><a class="anchor" id="Example"></a>
Example</h1>
<p>We start with the short format, and two matrices, one of double precision, and the other of single precision.</p>
<pre class="fragment">--&gt; format short
--&gt; 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 

--&gt; 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 
</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</p>
<pre class="fragment">--&gt; format long
--&gt; 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 

--&gt; 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 
</pre><p>Note also that we we scale the contents of the matrices, FreeMat rescales the entries with a scale premultiplier.</p>
<pre class="fragment">--&gt; format short
--&gt; 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 

--&gt; 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 

--&gt; 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 

--&gt; 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 
</pre><p>Next, we use the exponential formats:</p>
<pre class="fragment">--&gt; format short e
--&gt; 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 

--&gt; 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 

--&gt; 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 

--&gt; 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 
</pre><p>Finally, if we assign the <code>format</code> function to a variable, we can retrieve the current format:</p>
<pre class="fragment">--&gt; format short
--&gt; t = format

t = 
short
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="index.html">FreeMat Documentation</a></li><li class="navelem"><a class="el" href="sec_io.html">Input/Ouput Functions</a></li>
    <li class="footer">Generated on Thu Jul 25 2013 17:17:38 for FreeMat by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
  </ul>
</div>
</body>
</html>