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
|
<html lang="en">
<head>
<title>Object Sizes - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Data-Types.html#Data-Types" title="Data Types">
<link rel="prev" href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types" title="User-defined Data Types">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Object-Sizes"></a>
Previous: <a rel="previous" accesskey="p" href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types">User-defined Data Types</a>,
Up: <a rel="up" accesskey="u" href="Data-Types.html#Data-Types">Data Types</a>
<hr>
</div>
<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.
<!-- data.cc -->
<p><a name="doc_002dndims"></a>
<div class="defun">
— Built-in Function: <b>ndims</b> (<var>a</var>)<var><a name="index-ndims-200"></a></var><br>
<blockquote><p>Returns the number of dimensions of array <var>a</var>.
For any array, the result will always be larger than or equal to 2.
Trailing singleton dimensions are not counted.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dcolumns"></a>
<div class="defun">
— Built-in Function: <b>columns</b> (<var>a</var>)<var><a name="index-columns-201"></a></var><br>
<blockquote><p>Return the number of columns of <var>a</var>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsize.html#doc_002dsize">size</a>, <a href="doc_002dnumel.html#doc_002dnumel">numel</a>, <a href="doc_002drows.html#doc_002drows">rows</a>, <a href="doc_002dlength.html#doc_002dlength">length</a>, <a href="doc_002disscalar.html#doc_002disscalar">isscalar</a>, <a href="doc_002disvector.html#doc_002disvector">isvector</a>, <a href="doc_002dismatrix.html#doc_002dismatrix">ismatrix</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002drows"></a>
<div class="defun">
— Built-in Function: <b>rows</b> (<var>a</var>)<var><a name="index-rows-202"></a></var><br>
<blockquote><p>Return the number of rows of <var>a</var>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsize.html#doc_002dsize">size</a>, <a href="doc_002dnumel.html#doc_002dnumel">numel</a>, <a href="doc_002dcolumns.html#doc_002dcolumns">columns</a>, <a href="doc_002dlength.html#doc_002dlength">length</a>, <a href="doc_002disscalar.html#doc_002disscalar">isscalar</a>, <a href="doc_002disvector.html#doc_002disvector">isvector</a>, <a href="doc_002dismatrix.html#doc_002dismatrix">ismatrix</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dnumel"></a>
<div class="defun">
— Built-in Function: <b>numel</b> (<var>a</var>)<var><a name="index-numel-203"></a></var><br>
<blockquote><p>Returns the number of elements in the object <var>a</var>.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsize.html#doc_002dsize">size</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dlength"></a>
<div class="defun">
— Built-in Function: <b>length</b> (<var>a</var>)<var><a name="index-length-204"></a></var><br>
<blockquote><p>Return the `length' of the object <var>a</var>. For matrix objects, the
length is the number of rows or columns, whichever is greater (this
odd definition is used for compatibility with <span class="sc">matlab</span>).
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dsize"></a>
<div class="defun">
— Built-in Function: <b>size</b> (<var>a, n</var>)<var><a name="index-size-205"></a></var><br>
<blockquote><p>Return the number rows and columns of <var>a</var>.
<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,
<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>
<p>If given a second argument, <code>size</code> will return the size of the
corresponding dimension. For example
<pre class="example"> size ([1, 2; 3, 4; 5, 6], 2)
2
</pre>
<p class="noindent">returns the number of columns in the given matrix.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dnumel.html#doc_002dnumel">numel</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002disempty"></a>
<div class="defun">
— Built-in Function: <b>isempty</b> (<var>a</var>)<var><a name="index-isempty-206"></a></var><br>
<blockquote><p>Return 1 if <var>a</var> is an empty matrix (either the number of rows, or
the number of columns, or both are zero). Otherwise, return 0.
</p></blockquote></div>
<!-- ov-null-mat.cc -->
<p><a name="doc_002disnull"></a>
<div class="defun">
— Built-in Function: <b>isnull</b> (<var>x</var>)<var><a name="index-isnull-207"></a></var><br>
<blockquote><p>Return 1 if <var>x</var> is a special null matrix, string or single quoted string.
Indexed assignment with such a value as 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:
<dl>
<dt><code>A(I) = []</code><dd>This should delete elements if <code>I</code> is nonempty.
<br><dt><code>X = []; A(I) = X</code><dd>This should give an error if <code>I</code> is nonempty.
</dl>
</p></blockquote></div>
<!-- ov.cc -->
<p><a name="doc_002dsizeof"></a>
<div class="defun">
— Built-in Function: <b>sizeof</b> (<var>val</var>)<var><a name="index-sizeof-208"></a></var><br>
<blockquote><p>Return the size of <var>val</var> in bytes
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dsize_005fequal"></a>
<div class="defun">
— Built-in Function: <b>size_equal</b> (<var>a, b, <small class="dots">...</small></var>)<var><a name="index-size_005fequal-209"></a></var><br>
<blockquote><p>Return true if the dimensions of all arguments agree.
Trailing singleton dimensions are ignored.
Called with a single argument, size_equal returns true.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dsize.html#doc_002dsize">size</a>, <a href="doc_002dnumel.html#doc_002dnumel">numel</a>.
</p></blockquote></div>
<!-- data.cc -->
<p><a name="doc_002dsqueeze"></a>
<div class="defun">
— Built-in Function: <b>squeeze</b> (<var>x</var>)<var><a name="index-squeeze-210"></a></var><br>
<blockquote><p>Remove singleton dimensions from <var>x</var> and return the result.
Note that for compatibility with <span class="sc">matlab</span>, all objects have
a minimum of two dimensions and row vectors are left unchanged.
</p></blockquote></div>
<!-- DO NOT EDIT! Generated automatically by munge-texi. -->
<!-- Copyright (C) 1996, 1997, 2007, 2008, 2009 John W. Eaton -->
<!-- This file is part of Octave. -->
<!-- Octave is free software; you can redistribute it and/or modify it -->
<!-- under the terms of the GNU General Public License as published by the -->
<!-- Free Software Foundation; either version 3 of the License, or (at -->
<!-- your option) any later version. -->
<!-- Octave is distributed in the hope that it will be useful, but WITHOUT -->
<!-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -->
<!-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -->
<!-- for more details. -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with Octave; see the file COPYING. If not, see -->
<!-- <http://www.gnu.org/licenses/>. -->
</body></html>
|