2679
|
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 |
|
5 @node Data Types, Numeric Data Types, Getting Started, Top |
|
6 @chapter Data Types |
|
7 @cindex data types |
|
8 |
|
9 All versions of Octave include a number of built-in data types, |
|
10 including real and complex scalars and matrices, character strings, and |
|
11 a data structure type. |
|
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 |
|
17 Functions} for more information about Octave's dynamic linking |
2689
|
18 capabilities. @ref{User-defined Data Types} describes what you must do |
|
19 to define a new data type for Octave. |
2679
|
20 |
|
21 @menu |
|
22 * Built-in Data Types:: |
|
23 * User-defined Data Types:: |
|
24 * Object Sizes:: |
|
25 @end menu |
|
26 |
|
27 @node Built-in Data Types, User-defined Data Types, Data Types, Data Types |
|
28 @section Built-in Data Types |
|
29 @cindex data types, built-in |
|
30 @cindex built-in data types |
|
31 |
|
32 The standard built-in data types are real and complex scalars and |
2689
|
33 matrices, ranges, character strings, and a data structure type. |
|
34 Additional built-in data types may be added in future versions. If you |
|
35 need a specialized data type that is not currently provided as a |
|
36 built-in type, you are encouraged to write your own user-defined data |
|
37 type and contribute it for distribution in a future release of Octave. |
2679
|
38 |
|
39 @menu |
|
40 * Numeric Objects:: |
|
41 * String Objects:: |
|
42 * Data Structure Objects:: |
|
43 @end menu |
|
44 |
|
45 @node Numeric Objects, String Objects, Built-in Data Types, Built-in Data Types |
|
46 @subsection Numeric Objects |
|
47 @cindex numeric constant |
|
48 @cindex numeric value |
|
49 |
|
50 Octave's built-in numeric objects include real and complex scalars and |
|
51 matrices. All built-in numeric data is currently stored as double |
|
52 precision numbers. On systems that use the IEEE floating point format, |
2689
|
53 values in the range of approximately |
2679
|
54 @iftex |
|
55 @tex |
|
56 $2.2251\times10^{-308}$ to $1.7977\times10^{308}$ |
|
57 @end tex |
|
58 @end iftex |
|
59 @ifinfo |
|
60 2.2251e-308 to 1.7977e+308 |
|
61 @end ifinfo |
|
62 can be stored, and the relative precision is approximately |
|
63 @iftex |
|
64 @tex |
|
65 $2.2204\times10^{-16}$. |
|
66 @end tex |
|
67 @end iftex |
|
68 @ifinfo |
|
69 2.2204e-16. |
|
70 @end ifinfo |
2689
|
71 The exact values are given by the variables @code{realmin}, |
|
72 @code{realmax}, and @code{eps}, respectively. |
2679
|
73 |
|
74 Matrix objects can be of any size, and can be dynamically reshaped and |
|
75 resized. It is easy to extract individual rows, columns, or submatrices |
2689
|
76 is using a variety of powerful indexing features. @xref{Index Expressions}. |
2679
|
77 |
|
78 @xref{Numeric Data Types}, for more information. |
|
79 |
|
80 @node String Objects, Data Structure Objects, Numeric Objects, Built-in Data Types |
|
81 @subsection String Objects |
|
82 @cindex strings |
|
83 @cindex character strings |
|
84 @opindex " |
|
85 @opindex ' |
|
86 |
|
87 A character string in Octave consists of a sequence of characters |
|
88 enclosed in either double-quote or single-quote marks. Internally, |
|
89 Octave currently stores strings as matrices of characters. All the |
|
90 indexing operations that work for matrix objects also work for strings. |
|
91 |
|
92 @xref{Strings}, for more information. |
|
93 |
|
94 @node Data Structure Objects, , String Objects, Built-in Data Types |
|
95 @subsection Data Structure Objects |
|
96 @cindex structures |
|
97 @cindex data structures |
|
98 |
|
99 Octave's data structure type can help you to organize related objects of |
|
100 different types. The current implementation uses an associative array |
|
101 with indices limited to strings, but the syntax is more like C-style |
|
102 structures. |
|
103 |
|
104 @xref{Data Structures}, for more information. |
|
105 |
|
106 @node User-defined Data Types, Object Sizes, Built-in Data Types, Data Types |
|
107 @section User-defined Data Types |
|
108 @cindex user-defined data types |
|
109 @cindex data types, user-defined |
|
110 |
2689
|
111 Someday I hope to expand this to include a complete description of |
|
112 Octave's mechanism for managing user-defined data types. Until this |
|
113 feature is documented here, you will have to make do by reading the code |
|
114 in the @file{ov.h}, @file{ops.h}, and related files from Octave's |
|
115 @file{src} directory. |
|
116 |
2679
|
117 @node Object Sizes, , User-defined Data Types, Data Types |
|
118 @section Object Sizes |
|
119 |
|
120 The following functions allow you to determine the size of a variable or |
|
121 expression. These functions are defined for all objects. They return |
2689
|
122 @minus{}1 when the operation doesn't make sense. For example, Octave's |
|
123 data structure type doesn't have rows or columns, so the @code{rows} and |
|
124 @code{columns} functions return @minus{}1 for structure arguments. |
2679
|
125 |
|
126 @deftypefn {Function File} {} columns (@var{a}) |
|
127 Return the number of columns of @var{a}. |
|
128 @end deftypefn |
|
129 |
|
130 @deftypefn {Function File} {} rows (@var{a}) |
|
131 Return the number of rows of @var{a}. |
|
132 @end deftypefn |
|
133 |
|
134 @deftypefn {Function File} {} length (@var{a}) |
|
135 Return the number of rows of @var{a} or the number of columns of |
|
136 @var{a}, whichever is larger. |
|
137 @end deftypefn |
|
138 |
|
139 @deftypefn {Function File} {} size (@var{a}, @var{n}) |
|
140 Return the number rows and columns of @var{a}. |
|
141 |
|
142 With one input argument and one output argument, the result is returned |
|
143 in a 2 element row vector. If there are two output arguments, the |
|
144 number of rows is assigned to the first, and the number of columns to |
|
145 the second. For example, |
|
146 |
|
147 @example |
|
148 @group |
2689
|
149 size ([1, 2; 3, 4; 5, 6]) |
|
150 @result{} [ 3, 2 ] |
2679
|
151 |
2689
|
152 [nr, nc] = size ([1, 2; 3, 4; 5, 6]) |
|
153 @result{} nr = 3 |
|
154 @result{} nc = 2 |
2679
|
155 @end group |
|
156 @end example |
|
157 |
|
158 If given a second argument of either 1 or 2, @code{size} will return |
|
159 only the row or column dimension. For example |
|
160 |
|
161 @example |
2689
|
162 size ([1, 2; 3, 4; 5, 6], 2) |
|
163 @result{} 2 |
2679
|
164 @end example |
|
165 |
|
166 @noindent |
|
167 returns the number of columns in the given matrix. |
|
168 @end deftypefn |
|
169 |
|
170 @deftypefn {Function File} {} isempty (@var{a}) |
|
171 Return 1 if @var{a} is an empty matrix (either the number of rows, or |
|
172 the number of columns, or both are zero). Otherwise, return 0. |
|
173 @end deftypefn |
|
174 |