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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: Object Sizes</title>
<meta name="description" content="GNU Octave: Object Sizes">
<meta name="keywords" content="GNU Octave: Object Sizes">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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-Data-Types.html#Numeric-Data-Types" rel="next" title="Numeric Data Types">
<link href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" rel="prev" title="User-defined Data Types">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
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.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Object-Sizes"></a>
<div class="header">
<p>
Previous: <a href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" accesskey="p" rel="prev">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="Object-Sizes-1"></a>
<h3 class="section">3.3 Object Sizes</h3>
<p>The following functions allow you to determine the size of a variable or
expression. These functions are defined for all objects. They return
-1 when the operation doesn’t make sense. For example, Octave’s
data structure type doesn’t have rows or columns, so the <code>rows</code> and
<code>columns</code> functions return -1 for structure arguments.
</p>
<a name="XREFndims"></a><dl>
<dt><a name="index-ndims"></a>Built-in Function: <em></em> <strong>ndims</strong> <em>(<var>a</var>)</em></dt>
<dd><p>Return the number of dimensions of <var>a</var>.
For any array, the result will always be larger than or equal to 2.
Trailing singleton dimensions are not counted.
</p>
<div class="example">
<pre class="example">ndims (ones (4, 1, 2, 1))
⇒ 3
</pre></div>
<p><strong>See also:</strong> <a href="#XREFsize">size</a>.
</p></dd></dl>
<a name="XREFcolumns"></a><dl>
<dt><a name="index-columns"></a>Built-in Function: <em></em> <strong>columns</strong> <em>(<var>a</var>)</em></dt>
<dd><p>Return the number of columns of <var>a</var>.
</p>
<p><strong>See also:</strong> <a href="#XREFrows">rows</a>, <a href="#XREFsize">size</a>, <a href="#XREFlength">length</a>, <a href="#XREFnumel">numel</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisscalar">isscalar</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisvector">isvector</a>, <a href="Predicates-for-Numeric-Objects.html#XREFismatrix">ismatrix</a>.
</p></dd></dl>
<a name="XREFrows"></a><dl>
<dt><a name="index-rows"></a>Built-in Function: <em></em> <strong>rows</strong> <em>(<var>a</var>)</em></dt>
<dd><p>Return the number of rows of <var>a</var>.
</p>
<p><strong>See also:</strong> <a href="#XREFcolumns">columns</a>, <a href="#XREFsize">size</a>, <a href="#XREFlength">length</a>, <a href="#XREFnumel">numel</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisscalar">isscalar</a>, <a href="Predicates-for-Numeric-Objects.html#XREFisvector">isvector</a>, <a href="Predicates-for-Numeric-Objects.html#XREFismatrix">ismatrix</a>.
</p></dd></dl>
<a name="XREFnumel"></a><dl>
<dt><a name="index-numel"></a>Built-in Function: <em></em> <strong>numel</strong> <em>(<var>a</var>)</em></dt>
<dt><a name="index-numel-1"></a>Built-in Function: <em></em> <strong>numel</strong> <em>(<var>a</var>, <var>idx1</var>, <var>idx2</var>, …)</em></dt>
<dd><p>Return the number of elements in the object <var>a</var>.
Optionally, if indices <var>idx1</var>, <var>idx2</var>, … are supplied,
return the number of elements that would result from the indexing
</p>
<div class="example">
<pre class="example"><var>a</var>(<var>idx1</var>, <var>idx2</var>, …)
</pre></div>
<p>Note that the indices do not have to be numerical. For example,
</p>
<div class="example">
<pre class="example"><var>a</var> = 1;
<var>b</var> = ones (2, 3);
numel (<var>a</var>, <var>b</var>)
</pre></div>
<p>will return 6, as this is the number of ways to index with <var>b</var>.
</p>
<p>This method is also called when an object appears as lvalue with cs-list
indexing, i.e., <code>object{…}</code> or <code>object(…).field</code>.
</p>
<p><strong>See also:</strong> <a href="#XREFsize">size</a>.
</p></dd></dl>
<a name="XREFlength"></a><dl>
<dt><a name="index-length"></a>Built-in Function: <em></em> <strong>length</strong> <em>(<var>a</var>)</em></dt>
<dd><p>Return the length of the object <var>a</var>.
</p>
<p>The length is 0 for empty objects, 1 for scalars, and the number of elements
for vectors. For matrix objects, the length is the number of rows or
columns, whichever is greater (this odd definition is used for compatibility
with <small>MATLAB</small>).
</p>
<p><strong>See also:</strong> <a href="#XREFnumel">numel</a>, <a href="#XREFsize">size</a>.
</p></dd></dl>
<a name="XREFsize"></a><dl>
<dt><a name="index-size"></a>Built-in Function: <em></em> <strong>size</strong> <em>(<var>a</var>)</em></dt>
<dt><a name="index-size-1"></a>Built-in Function: <em></em> <strong>size</strong> <em>(<var>a</var>, <var>dim</var>)</em></dt>
<dd><p>Return the number of rows and columns of <var>a</var>.
</p>
<p>With one input argument and one output argument, the result is returned
in a row vector. If there are multiple output arguments, the number of
rows is assigned to the first, and the number of columns to the second,
etc. For example:
</p>
<div class="example">
<pre class="example">size ([1, 2; 3, 4; 5, 6])
⇒ [ 3, 2 ]
[nr, nc] = size ([1, 2; 3, 4; 5, 6])
⇒ nr = 3
⇒ nc = 2
</pre></div>
<p>If given a second argument, <code>size</code> will return the size of the
corresponding dimension. For example,
</p>
<div class="example">
<pre class="example">size ([1, 2; 3, 4; 5, 6], 2)
⇒ 2
</pre></div>
<p>returns the number of columns in the given matrix.
</p>
<p><strong>See also:</strong> <a href="#XREFnumel">numel</a>, <a href="#XREFndims">ndims</a>, <a href="#XREFlength">length</a>, <a href="#XREFrows">rows</a>, <a href="#XREFcolumns">columns</a>.
</p></dd></dl>
<a name="XREFisempty"></a><dl>
<dt><a name="index-isempty"></a>Built-in Function: <em></em> <strong>isempty</strong> <em>(<var>a</var>)</em></dt>
<dd><p>Return true if <var>a</var> is an empty matrix (any one of its dimensions is
zero). Otherwise, return false.
</p>
<p><strong>See also:</strong> <a href="#XREFisnull">isnull</a>, <a href="Built_002din-Data-Types.html#XREFisa">isa</a>.
</p></dd></dl>
<a name="XREFisnull"></a><dl>
<dt><a name="index-isnull"></a>Built-in Function: <em></em> <strong>isnull</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Return true if <var>x</var> is a special null matrix, string, or single quoted
string. Indexed assignment with such a value on the right-hand side should
delete array elements. This function should be used when overloading
indexed assignment for user-defined classes instead of <code>isempty</code>, to
distinguish the cases:
</p>
<dl compact="compact">
<dt><code>A(I) = []</code></dt>
<dd><p>This should delete elements if <code>I</code> is nonempty.
</p>
</dd>
<dt><code>X = []; A(I) = X</code></dt>
<dd><p>This should give an error if <code>I</code> is nonempty.
</p></dd>
</dl>
<p><strong>See also:</strong> <a href="#XREFisempty">isempty</a>, <a href="Advanced-Indexing.html#XREFisindex">isindex</a>.
</p></dd></dl>
<a name="XREFsizeof"></a><dl>
<dt><a name="index-sizeof"></a>Built-in Function: <em></em> <strong>sizeof</strong> <em>(<var>val</var>)</em></dt>
<dd><p>Return the size of <var>val</var> in bytes.
</p>
<p><strong>See also:</strong> <a href="Status-of-Variables.html#XREFwhos">whos</a>.
</p></dd></dl>
<a name="XREFsize_005fequal"></a><dl>
<dt><a name="index-size_005fequal"></a>Built-in Function: <em></em> <strong>size_equal</strong> <em>(<var>a</var>, <var>b</var>, …)</em></dt>
<dd><p>Return true if the dimensions of all arguments agree.
Trailing singleton dimensions are ignored.
Called with a single or no argument, size_equal returns true.
</p>
<p><strong>See also:</strong> <a href="#XREFsize">size</a>, <a href="#XREFnumel">numel</a>, <a href="#XREFndims">ndims</a>.
</p></dd></dl>
<a name="XREFsqueeze"></a><dl>
<dt><a name="index-squeeze"></a>Built-in Function: <em></em> <strong>squeeze</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Remove singleton dimensions from <var>x</var> and return the result.
Note that for compatibility with <small>MATLAB</small>, all objects have
a minimum of two dimensions and row vectors are left unchanged.
</p>
<p><strong>See also:</strong> <a href="Rearranging-Matrices.html#XREFreshape">reshape</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Previous: <a href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" accesskey="p" rel="prev">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>
|