File: Object-Sizes.html

package info (click to toggle)
octave 3.6.2-5%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 71,636 kB
  • sloc: cpp: 241,186; fortran: 23,651; sh: 14,790; ansic: 7,153; lex: 3,761; objc: 3,404; yacc: 3,386; makefile: 2,073; awk: 985; perl: 838
file content (243 lines) | stat: -rw-r--r-- 11,743 bytes parent folder | download
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
242
243
<html lang="en">
<head>
<title>Object Sizes - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<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">
<a name="Object-Sizes"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="User_002ddefined-Data-Types.html#User_002ddefined-Data-Types">User-defined Data Types</a>,
Up:&nbsp;<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
&minus;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 &minus;1 for structure arguments.

<!-- ndims src/data.cc -->
   <p><a name="doc_002dndims"></a>

<div class="defun">
&mdash; Built-in Function:  <b>ndims</b> (<var>a</var>)<var><a name="index-ndims-228"></a></var><br>
<blockquote><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.

     <pre class="example">            ndims (ones (4, 1, 2, 1))
               &rArr; 3
</pre>
        </blockquote></div>

<!-- columns src/data.cc -->
   <p><a name="doc_002dcolumns"></a>

<div class="defun">
&mdash; Built-in Function:  <b>columns</b> (<var>a</var>)<var><a name="index-columns-229"></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_002drows.html#doc_002drows">rows</a>, <a href="doc_002dsize.html#doc_002dsize">size</a>, <a href="doc_002dlength.html#doc_002dlength">length</a>, <a href="doc_002dnumel.html#doc_002dnumel">numel</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>

<!-- rows src/data.cc -->
   <p><a name="doc_002drows"></a>

<div class="defun">
&mdash; Built-in Function:  <b>rows</b> (<var>a</var>)<var><a name="index-rows-230"></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_002dcolumns.html#doc_002dcolumns">columns</a>, <a href="doc_002dsize.html#doc_002dsize">size</a>, <a href="doc_002dlength.html#doc_002dlength">length</a>, <a href="doc_002dnumel.html#doc_002dnumel">numel</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>

<!-- numel src/data.cc -->
   <p><a name="doc_002dnumel"></a>

<div class="defun">
&mdash; Built-in Function:  <b>numel</b> (<var>a</var>)<var><a name="index-numel-231"></a></var><br>
&mdash; Built-in Function:  <b>numel</b> (<var>a, idx1, idx2, <small class="dots">...</small></var>)<var><a name="index-numel-232"></a></var><br>
<blockquote><p>Return the number of elements in the object <var>a</var>. 
Optionally, if indices <var>idx1</var>, <var>idx2</var>, <small class="dots">...</small> are supplied,
return the number of elements that would result from the indexing

     <pre class="example">            <var>a</var>(<var>idx1</var>, <var>idx2</var>, ...)
</pre>
        <p>Note that the indices do not have to be numerical.  For example,

     <pre class="example">            <var>a</var> = 1;
            <var>b</var> = ones (2, 3);
            numel (<var>a</var>, <var>b</var>);
</pre>
        <p class="noindent">will return 6, as this is the number of ways to index with <var>b</var>.

        <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>. 
<!-- 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>

<!-- length src/data.cc -->
   <p><a name="doc_002dlength"></a>

<div class="defun">
&mdash; Built-in Function:  <b>length</b> (<var>a</var>)<var><a name="index-length-233"></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>

<!-- size src/data.cc -->
   <p><a name="doc_002dsize"></a>

<div class="defun">
&mdash; Built-in Function:  <b>size</b> (<var>a</var>)<var><a name="index-size-234"></a></var><br>
&mdash; Built-in Function:  <b>size</b> (<var>a, dim</var>)<var><a name="index-size-235"></a></var><br>
<blockquote><p>Return the number of 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])
               &rArr; [ 3, 2 ]
          
          [nr, nc] = size ([1, 2; 3, 4; 5, 6])
               &rArr; nr = 3
               &rArr; 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)
               &rArr; 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>

<!-- isempty src/data.cc -->
   <p><a name="doc_002disempty"></a>

<div class="defun">
&mdash; Built-in Function:  <b>isempty</b> (<var>a</var>)<var><a name="index-isempty-236"></a></var><br>
<blockquote><p>Return true if <var>a</var> is an empty matrix (any one of its dimensions is
zero).  Otherwise, return false. 
<!-- 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_002disnull.html#doc_002disnull">isnull</a>. 
</p></blockquote></div>

<!-- isnull src/ov-null-mat.cc -->
   <p><a name="doc_002disnull"></a>

<div class="defun">
&mdash; Built-in Function:  <b>isnull</b> (<var>x</var>)<var><a name="index-isnull-237"></a></var><br>
<blockquote><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:
          <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>
        <!-- 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_002disempty.html#doc_002disempty">isempty</a>, <a href="doc_002disindex.html#doc_002disindex">isindex</a>. 
</p></blockquote></div>

<!-- sizeof src/ov.cc -->
   <p><a name="doc_002dsizeof"></a>

<div class="defun">
&mdash; Built-in Function:  <b>sizeof</b> (<var>val</var>)<var><a name="index-sizeof-238"></a></var><br>
<blockquote><p>Return the size of <var>val</var> in bytes. 
<!-- 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_002dwhos.html#doc_002dwhos">whos</a>. 
</p></blockquote></div>

<!-- size_equal src/data.cc -->
   <p><a name="doc_002dsize_005fequal"></a>

<div class="defun">
&mdash; Built-in Function:  <b>size_equal</b> (<var>a, b, <small class="dots">...</small></var>)<var><a name="index-size_005fequal-239"></a></var><br>
<blockquote><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. 
<!-- 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>

<!-- squeeze src/data.cc -->
   <p><a name="doc_002dsqueeze"></a>

<div class="defun">
&mdash; Built-in Function:  <b>squeeze</b> (<var>x</var>)<var><a name="index-squeeze-240"></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-2012 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>