<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Built-in Data Types (GNU Octave (version 5.1.0))</title> <meta name="description" content="Built-in Data Types (GNU Octave (version 5.1.0))"> <meta name="keywords" content="Built-in Data Types (GNU Octave (version 5.1.0))"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <link href="index.html#Top" rel="start" title="Top"> <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="Data-Types.html#Data-Types" rel="up" title="Data Types"> <link href="Numeric-Objects.html#Numeric-Objects" rel="next" title="Numeric Objects"> <link href="Data-Types.html#Data-Types" rel="prev" title="Data Types"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smalllisp {margin-left: 3.2em} kbd {font-style: oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nolinebreak {white-space: nowrap} span.roman {font-family: initial; font-weight: normal} span.sansserif {font-family: sans-serif; font-weight: normal} ul.no-bullet {list-style: none} --> </style> <link rel="stylesheet" type="text/css" href="octave.css"> </head> <body lang="en"> <a name="Built_002din-Data-Types"></a> <div class="header"> <p> Next: <a href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" accesskey="n" rel="next">User-defined Data Types</a>, Up: <a href="Data-Types.html#Data-Types" accesskey="u" rel="up">Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <hr> <a name="Built_002din-Data-Types-1"></a> <h3 class="section">3.1 Built-in Data Types</h3> <a name="index-data-types_002c-built_002din"></a> <a name="index-built_002din-data-types"></a> <p>The standard built-in data types are real and complex scalars and matrices, ranges, character strings, a data structure type, and cell arrays. Additional built-in data types may be added in future versions. If you need a specialized data type that is not currently provided as a built-in type, you are encouraged to write your own user-defined data type and contribute it for distribution in a future release of Octave. </p> <p>The data type of a variable can be determined and changed through the use of the following functions. </p> <a name="XREFclass"></a><dl> <dt><a name="index-class"></a><em><var>classname</var> =</em> <strong>class</strong> <em>(<var>obj</var>)</em></dt> <dt><a name="index-class-1"></a><em></em> <strong>class</strong> <em>(<var>s</var>, <var>id</var>)</em></dt> <dt><a name="index-class-2"></a><em></em> <strong>class</strong> <em>(<var>s</var>, <var>id</var>, <var>p</var>, …)</em></dt> <dd><p>Return the class of the object <var>obj</var>, or create a class with fields from structure <var>s</var> and name (string) <var>id</var>. </p> <p>Additional arguments name a list of parent classes from which the new class is derived. </p> <p><strong>See also:</strong> <a href="Data-Types.html#XREFtypeinfo">typeinfo</a>, <a href="#XREFisa">isa</a>. </p></dd></dl> <a name="XREFisa"></a><dl> <dt><a name="index-isa"></a><em></em> <strong>isa</strong> <em>(<var>obj</var>, <var>classname</var>)</em></dt> <dd><p>Return true if <var>obj</var> is an object from the class <var>classname</var>. </p> <p><var>classname</var> may also be one of the following class categories: </p> <dl compact="compact"> <dt><code>"float"</code></dt> <dd><p>Floating point value comprising classes <code>"double"</code> and <code>"single"</code>. </p> </dd> <dt><code>"integer"</code></dt> <dd><p>Integer value comprising classes (u)int8, (u)int16, (u)int32, (u)int64. </p> </dd> <dt><code>"numeric"</code></dt> <dd><p>Numeric value comprising either a floating point or integer value. </p></dd> </dl> <p>If <var>classname</var> is a cell array of string, a logical array of the same size is returned, containing true for each class to which <var>obj</var> belongs to. </p> <p><strong>See also:</strong> <a href="#XREFclass">class</a>, <a href="Data-Types.html#XREFtypeinfo">typeinfo</a>. </p></dd></dl> <a name="XREFcast"></a><dl> <dt><a name="index-cast"></a><em></em> <strong>cast</strong> <em>(<var>val</var>, "<var>type</var>")</em></dt> <dd><p>Convert <var>val</var> to data type <var>type</var>. </p> <p>Both <var>val</var> and <var>type</var> are typically one of the following built-in classes: </p> <div class="example"> <pre class="example">"double" "single" "logical" "char" "int8" "int16" "int32" "int64" "uint8" "uint16" "uint32" "uint64" </pre></div> <p>The value <var>val</var> may be modified to fit within the range of the new type. </p> <p>Examples: </p> <div class="example"> <pre class="example">cast (-5, "uint8") ⇒ 0 cast (300, "int8") ⇒ 127 </pre></div> <p>Programming Note: This function relies on the object <var>val</var> having a conversion method named <var>type</var>. User-defined classes may implement only a subset of the full list of types shown above. In that case, it may be necessary to call cast twice in order to reach the desired type. For example, the conversion to double is nearly always implemented, but the conversion to uint8 might not be. In that case, the following code will work </p> <div class="example"> <pre class="example">cast (cast (<var>user_defined_val</var>, "double"), "uint8") </pre></div> <p><strong>See also:</strong> <a href="#XREFtypecast">typecast</a>, <a href="Integer-Data-Types.html#XREFint8">int8</a>, <a href="Integer-Data-Types.html#XREFuint8">uint8</a>, <a href="Integer-Data-Types.html#XREFint16">int16</a>, <a href="Integer-Data-Types.html#XREFuint16">uint16</a>, <a href="Integer-Data-Types.html#XREFint32">int32</a>, <a href="Integer-Data-Types.html#XREFuint32">uint32</a>, <a href="Integer-Data-Types.html#XREFint64">int64</a>, <a href="Integer-Data-Types.html#XREFuint64">uint64</a>, <a href="Numeric-Data-Types.html#XREFdouble">double</a>, <a href="Single-Precision-Data-Types.html#XREFsingle">single</a>, <a href="Logical-Values.html#XREFlogical">logical</a>, <a href="Concatenating-Strings.html#XREFchar">char</a>, <a href="#XREFclass">class</a>, <a href="Data-Types.html#XREFtypeinfo">typeinfo</a>. </p></dd></dl> <a name="XREFtypecast"></a><dl> <dt><a name="index-typecast"></a><em><var>y</var> =</em> <strong>typecast</strong> <em>(<var>x</var>, "<var>class</var>")</em></dt> <dd><p>Return a new array <var>y</var> resulting from interpreting the data of <var>x</var> in memory as data of the numeric class <var>class</var>. </p> <p>Both the class of <var>x</var> and <var>class</var> must be one of the built-in numeric classes: </p> <div class="example"> <pre class="example">"logical" "char" "int8" "int16" "int32" "int64" "uint8" "uint16" "uint32" "uint64" "double" "single" "double complex" "single complex" </pre></div> <p>the last two are only used with <var>class</var>; they indicate that a complex-valued result is requested. Complex arrays are stored in memory as consecutive pairs of real numbers. The sizes of integer types are given by their bit counts. Both logical and char are typically one byte wide; however, this is not guaranteed by C++. If your system is IEEE conformant, single and double will be 4 bytes and 8 bytes wide, respectively. <code>"logical"</code> is not allowed for <var>class</var>. </p> <p>If the input is a row vector, the return value is a row vector, otherwise it is a column vector. </p> <p>If the bit length of <var>x</var> is not divisible by that of <var>class</var>, an error occurs. </p> <p>An example of the use of typecast on a little-endian machine is </p> <div class="example"> <pre class="example"><var>x</var> = uint16 ([1, 65535]); typecast (<var>x</var>, "uint8") ⇒ [ 1, 0, 255, 255] </pre></div> <p><strong>See also:</strong> <a href="#XREFcast">cast</a>, <a href="#XREFbitpack">bitpack</a>, <a href="#XREFbitunpack">bitunpack</a>, <a href="#XREFswapbytes">swapbytes</a>. </p></dd></dl> <a name="XREFswapbytes"></a><dl> <dt><a name="index-swapbytes"></a><em></em> <strong>swapbytes</strong> <em>(<var>x</var>)</em></dt> <dd><p>Swap the byte order on values, converting from little endian to big endian and vice versa. </p> <p>For example: </p> <div class="example"> <pre class="example">swapbytes (uint16 (1:4)) ⇒ 256 512 768 1024 </pre></div> <p><strong>See also:</strong> <a href="#XREFtypecast">typecast</a>, <a href="#XREFcast">cast</a>. </p></dd></dl> <a name="XREFbitpack"></a><dl> <dt><a name="index-bitpack"></a><em><var>y</var> =</em> <strong>bitpack</strong> <em>(<var>x</var>, <var>class</var>)</em></dt> <dd><p>Return a new array <var>y</var> resulting from interpreting the logical array <var>x</var> as raw bit patterns for data of the numeric class <var>class</var>. </p> <p><var>class</var> must be one of the built-in numeric classes: </p> <div class="example"> <pre class="example">"double" "single" "double complex" "single complex" "char" "int8" "int16" "int32" "int64" "uint8" "uint16" "uint32" "uint64" </pre></div> <p>The number of elements of <var>x</var> should be divisible by the bit length of <var>class</var>. If it is not, excess bits are discarded. Bits come in increasing order of significance, i.e., <code>x(1)</code> is bit 0, <code>x(2)</code> is bit 1, etc. </p> <p>The result is a row vector if <var>x</var> is a row vector, otherwise it is a column vector. </p> <p><strong>See also:</strong> <a href="#XREFbitunpack">bitunpack</a>, <a href="#XREFtypecast">typecast</a>. </p></dd></dl> <a name="XREFbitunpack"></a><dl> <dt><a name="index-bitunpack"></a><em><var>y</var> =</em> <strong>bitunpack</strong> <em>(<var>x</var>)</em></dt> <dd><p>Return a logical array <var>y</var> corresponding to the raw bit patterns of <var>x</var>. </p> <p><var>x</var> must belong to one of the built-in numeric classes: </p> <div class="example"> <pre class="example">"double" "single" "char" "int8" "int16" "int32" "int64" "uint8" "uint16" "uint32" "uint64" </pre></div> <p>The result is a row vector if <var>x</var> is a row vector; otherwise, it is a column vector. </p> <p><strong>See also:</strong> <a href="#XREFbitpack">bitpack</a>, <a href="#XREFtypecast">typecast</a>. </p></dd></dl> <table class="menu" border="0" cellspacing="0"> <tr><td align="left" valign="top">• <a href="Numeric-Objects.html#Numeric-Objects" accesskey="1">Numeric Objects</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="Missing-Data.html#Missing-Data" accesskey="2">Missing Data</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="String-Objects.html#String-Objects" accesskey="3">String Objects</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="Data-Structure-Objects.html#Data-Structure-Objects" accesskey="4">Data Structure Objects</a>:</td><td> </td><td align="left" valign="top"> </td></tr> <tr><td align="left" valign="top">• <a href="Cell-Array-Objects.html#Cell-Array-Objects" accesskey="5">Cell Array Objects</a>:</td><td> </td><td align="left" valign="top"> </td></tr> </table> <hr> <div class="header"> <p> Next: <a href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" accesskey="n" rel="next">User-defined Data Types</a>, Up: <a href="Data-Types.html#Data-Types" accesskey="u" rel="up">Data Types</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> </body> </html>