3294
|
1 @c Copyright (C) 1996, 1997 John W. Eaton |
|
2 @c This is part of the Octave manual. |
|
3 @c For copying conditions, see the file gpl.texi. |
|
4 |
4167
|
5 @node Data Types |
3294
|
6 @chapter Data Types |
|
7 @cindex data types |
|
8 |
|
9 All versions of Octave include a number of built-in data types, |
6620
|
10 including real and complex scalars and matrices, character strings, |
|
11 a data structure type, and an array that can contain all data types. |
3294
|
12 |
|
13 It is also possible to define new specialized data types by writing a |
|
14 small amount of C++ code. On some systems, new data types can be loaded |
|
15 dynamically while Octave is running, so it is not necessary to recompile |
|
16 all of Octave just to add a new type. @xref{Dynamically Linked |
3402
|
17 Functions}, for more information about Octave's dynamic linking |
3294
|
18 capabilities. @ref{User-defined Data Types} describes what you must do |
|
19 to define a new data type for Octave. |
|
20 |
3428
|
21 @DOCSTRING(typeinfo) |
|
22 |
3294
|
23 @menu |
|
24 * Built-in Data Types:: |
|
25 * User-defined Data Types:: |
|
26 * Object Sizes:: |
|
27 @end menu |
|
28 |
4167
|
29 @node Built-in Data Types |
3294
|
30 @section Built-in Data Types |
|
31 @cindex data types, built-in |
|
32 @cindex built-in data types |
|
33 |
|
34 The standard built-in data types are real and complex scalars and |
6620
|
35 matrices, ranges, character strings, a data structure type, and cell |
|
36 arrays. Additional built-in data types may be added in future versions. |
|
37 If you need a specialized data type that is not currently provided as a |
3294
|
38 built-in type, you are encouraged to write your own user-defined data |
|
39 type and contribute it for distribution in a future release of Octave. |
|
40 |
6620
|
41 The data type of a variable can be determined and changed through the |
|
42 use of the following functions. |
|
43 |
6550
|
44 @DOCSTRING(class) |
|
45 |
|
46 @DOCSTRING(isa) |
|
47 |
|
48 @DOCSTRING(cast) |
|
49 |
3294
|
50 @menu |
|
51 * Numeric Objects:: |
4169
|
52 * Missing Data:: |
3294
|
53 * String Objects:: |
|
54 * Data Structure Objects:: |
|
55 @end menu |
|
56 |
4167
|
57 @node Numeric Objects |
3294
|
58 @subsection Numeric Objects |
|
59 @cindex numeric constant |
|
60 @cindex numeric value |
|
61 |
6620
|
62 Octave's built-in numeric objects include real, complex, and integer |
|
63 scalars and matrices. All built-in floating point numeric data is |
|
64 currently stored as double precision numbers. On systems that use the |
|
65 IEEE floating point format, values in the range of approximately |
3294
|
66 @iftex |
|
67 @tex |
|
68 $2.2251\times10^{-308}$ to $1.7977\times10^{308}$ |
|
69 @end tex |
|
70 @end iftex |
6620
|
71 @ifnottex |
3294
|
72 2.2251e-308 to 1.7977e+308 |
6620
|
73 @end ifnottex |
3294
|
74 can be stored, and the relative precision is approximately |
|
75 @iftex |
|
76 @tex |
|
77 $2.2204\times10^{-16}$. |
|
78 @end tex |
|
79 @end iftex |
6620
|
80 @ifnottex |
3294
|
81 2.2204e-16. |
6620
|
82 @end ifnottex |
3294
|
83 The exact values are given by the variables @code{realmin}, |
|
84 @code{realmax}, and @code{eps}, respectively. |
|
85 |
|
86 Matrix objects can be of any size, and can be dynamically reshaped and |
|
87 resized. It is easy to extract individual rows, columns, or submatrices |
|
88 using a variety of powerful indexing features. @xref{Index Expressions}. |
|
89 |
|
90 @xref{Numeric Data Types}, for more information. |
|
91 |
4169
|
92 @node Missing Data |
|
93 @subsection Missing Data |
|
94 @cindex missing data |
|
95 |
6620
|
96 It is possible to represent missing data explicitly in Octave using |
|
97 @code{NA} (short for ``Not Available''). Missing data can only be |
|
98 represented when data is represented as floating point numbers. In this |
|
99 case missing data is represented as a special case of the representation |
|
100 of @code{NaN}. |
|
101 |
4169
|
102 @DOCSTRING(NA) |
|
103 |
|
104 @DOCSTRING(isna) |
|
105 |
4167
|
106 @node String Objects |
3294
|
107 @subsection String Objects |
|
108 @cindex strings |
|
109 @cindex character strings |
|
110 @opindex " |
|
111 @opindex ' |
|
112 |
|
113 A character string in Octave consists of a sequence of characters |
|
114 enclosed in either double-quote or single-quote marks. Internally, |
|
115 Octave currently stores strings as matrices of characters. All the |
|
116 indexing operations that work for matrix objects also work for strings. |
|
117 |
|
118 @xref{Strings}, for more information. |
|
119 |
4167
|
120 @node Data Structure Objects |
3294
|
121 @subsection Data Structure Objects |
|
122 @cindex structures |
|
123 @cindex data structures |
|
124 |
|
125 Octave's data structure type can help you to organize related objects of |
|
126 different types. The current implementation uses an associative array |
|
127 with indices limited to strings, but the syntax is more like C-style |
|
128 structures. |
|
129 |
|
130 @xref{Data Structures}, for more information. |
|
131 |
6620
|
132 @node Cell Array Objects |
|
133 @subsection Cell Array Objects |
|
134 @cindex cell arrays |
|
135 |
|
136 A Cell Array in Octave is general array that can hold any number of |
|
137 different data types. |
|
138 |
|
139 @xref{Cell Arrays}, for more information. |
|
140 |
4167
|
141 @node User-defined Data Types |
3294
|
142 @section User-defined Data Types |
|
143 @cindex user-defined data types |
|
144 @cindex data types, user-defined |
|
145 |
|
146 Someday I hope to expand this to include a complete description of |
|
147 Octave's mechanism for managing user-defined data types. Until this |
|
148 feature is documented here, you will have to make do by reading the code |
|
149 in the @file{ov.h}, @file{ops.h}, and related files from Octave's |
|
150 @file{src} directory. |
|
151 |
4167
|
152 @node Object Sizes |
3294
|
153 @section Object Sizes |
|
154 |
|
155 The following functions allow you to determine the size of a variable or |
|
156 expression. These functions are defined for all objects. They return |
|
157 @minus{}1 when the operation doesn't make sense. For example, Octave's |
|
158 data structure type doesn't have rows or columns, so the @code{rows} and |
|
159 @code{columns} functions return @minus{}1 for structure arguments. |
|
160 |
6549
|
161 @DOCSTRING(ndims) |
|
162 |
3373
|
163 @DOCSTRING(columns) |
3294
|
164 |
3373
|
165 @DOCSTRING(rows) |
3294
|
166 |
6549
|
167 @DOCSTRING(numel) |
|
168 |
3373
|
169 @DOCSTRING(length) |
3294
|
170 |
3373
|
171 @DOCSTRING(size) |
3294
|
172 |
3373
|
173 @DOCSTRING(isempty) |
3294
|
174 |
6549
|
175 @DOCSTRING(sizeof) |
|
176 |
|
177 @DOCSTRING(size_equal) |
6550
|
178 |
|
179 @DOCSTRING(squeeze) |