Mercurial > hg > octave-lyh
annotate doc/interpreter/expr.txi @ 14119:94e2a76f1e5a stable
doc: Final grammarcheck and spellcheck before 3.6.0 release.
* container.txi, aspell-octave.en.pws, expr.txi, vectorize.txi, accumarray.m,
accumdim.m, interpft.m, strread.m, parseparams.m, warning_ids.m, cellfun.cc,
help.cc: grammarcheck and spellcheck docstrings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 29 Dec 2011 06:05:00 -0800 |
parents | 951eacaf9381 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 @c Copyright (C) 1996-2011 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Expressions |
3294 | 20 @chapter Expressions |
21 @cindex expressions | |
22 | |
23 Expressions are the basic building block of statements in Octave. An | |
24 expression evaluates to a value, which you can print, test, store in a | |
25 variable, pass to a function, or assign a new value to a variable with | |
26 an assignment operator. | |
27 | |
28 An expression can serve as a statement on its own. Most other kinds of | |
29 statements contain one or more expressions which specify data to be | |
30 operated on. As in other languages, expressions in Octave include | |
31 variables, array references, constants, and function calls, as well as | |
32 combinations of these with various operators. | |
33 | |
34 @menu | |
35 * Index Expressions:: | |
36 * Calling Functions:: | |
37 * Arithmetic Ops:: | |
38 * Comparison Ops:: | |
39 * Boolean Expressions:: | |
40 * Assignment Ops:: | |
41 * Increment Ops:: | |
42 * Operator Precedence:: | |
43 @end menu | |
44 | |
4167 | 45 @node Index Expressions |
3294 | 46 @section Index Expressions |
47 | |
48 @opindex ( | |
49 @opindex ) | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
50 @opindex : |
3294 | 51 |
52 An @dfn{index expression} allows you to reference or extract selected | |
53 elements of a matrix or vector. | |
54 | |
55 Indices may be scalars, vectors, ranges, or the special operator | |
56 @samp{:}, which may be used to select entire rows or columns. | |
57 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
58 Vectors are indexed using a single index expression. Matrices (2-D) |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
59 and higher multi-dimensional arrays are indexed using either one index |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
60 or @math{N} indices where @math{N} is the dimension of the array. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
61 When using a single index expression to index 2-D or higher data the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
62 elements of the array are taken in column-first order (like Fortran). |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
63 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
64 The output from indexing assumes the dimensions of the index |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14033
diff
changeset
|
65 expression. For example: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
66 |
5679 | 67 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
68 @group |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
69 a(2) # result is a scalar |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
70 a(1:2) # result is a row vector |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
71 a([1; 2]) # result is a column vector |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
72 @end group |
5679 | 73 @end example |
74 | |
75 As a special case, when a colon is used as a single index, the output | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
76 is a column vector containing all the elements of the vector or |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
77 matrix. For example: |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
78 |
5679 | 79 @example |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14033
diff
changeset
|
80 @group |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
81 a(:) # result is a column vector |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
82 a(:)' # result is a row vector |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14033
diff
changeset
|
83 @end group |
5679 | 84 @end example |
85 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
86 The above two code idioms are often used in place of @code{reshape} |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
87 when a simple vector, rather than an arbitrarily sized array, is |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
88 needed. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
89 |
3294 | 90 Given the matrix |
91 | |
92 @example | |
93 a = [1, 2; 3, 4] | |
94 @end example | |
95 | |
96 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
97 all of the following expressions are equivalent and select the first |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
98 row of the matrix. |
3294 | 99 |
100 @example | |
101 @group | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
102 a(1, [1, 2]) # row 1, columns 1 and 2 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
103 a(1, 1:2) # row 1, columns in range 1-2 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
104 a(1, :) # row 1, all columns |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
105 @end group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
106 @end example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
107 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
108 @cindex @code{end}, indexing |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
109 @cindex :end |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
110 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
111 In index expressions the keyword @code{end} automatically refers to |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
112 the last entry for a particular dimension. This magic index can also |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
113 be used in ranges and typically eliminates the needs to call |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
114 @code{size} or @code{length} to gather array bounds before indexing. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
115 For example: |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
116 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
117 @example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
118 @group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
119 a = [1, 2, 3, 4]; |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
120 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
121 a(1:end/2) # first half of a => [1, 2] |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
122 a(end + 1) = 5; # append element |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
123 a(end) = []; # delete element |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
124 a(1:2:end) # odd elements of a => [1, 3] |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
125 a(2:2:end) # even elements of a => [2, 4] |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
126 a(end:-1:1) # reversal of a => [4, 3, 2 , 1] |
3294 | 127 @end group |
128 @end example | |
129 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
130 @menu |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
131 * Advanced Indexing:: |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
132 @end menu |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
133 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
134 @node Advanced Indexing |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
135 @subsection Advanced Indexing |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
136 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
137 An array with @samp{n} dimensions can be indexed using @samp{m} |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
138 indices. More generally, the set of index tuples determining the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
139 result is formed by the Cartesian product of the index vectors (or |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
140 ranges or scalars). |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
141 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
142 For the ordinary and most common case, @w{@code{m == n}}, and each |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
143 index corresponds to its respective dimension. If @w{@code{m < n}} |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
144 and every index is less than the size of the array in the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
145 @math{i^{th}} dimension, @code{m(i) < n(i)}, then the index expression |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
146 is padded with trailing singleton dimensions (@code{[ones (m-n, 1)]}). |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
147 If @w{@code{m < n}} but one of the indices @code{m(i)} is outside the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
148 size of the current array, then the last @w{@code{n-m+1}} dimensions |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
149 are folded into a single dimension with an extent equal to the product |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
150 of extents of the original dimensions. This is easiest to understand |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
151 with an example. |
3294 | 152 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
153 @example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
154 a = reshape (1:8, 2, 2, 2) # Create 3-D array |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
155 a = |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
156 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
157 ans(:,:,1) = |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
158 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
159 1 3 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
160 2 4 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
161 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
162 ans(:,:,2) = |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
163 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
164 5 7 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
165 6 8 |
9159 | 166 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
167 a(2,1,2); # Case (m == n): ans = 6 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
168 a(2,1); # Case (m < n), idx within array: |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
169 # equivalent to a(2,1,1), ans = 2 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
170 a(2,4); # Case (m < n), idx outside array: |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
171 # Dimension 2 & 3 folded into new dimension of size 2x2 = 4 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
172 # Select 2nd row, 4th element of [2, 4, 6, 8], ans = 8 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
173 @end example |
3294 | 174 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
175 One advanced use of indexing is to create arrays filled with a single |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
176 value. This can be done by using an index of ones on a scalar value. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
177 The result is an object with the dimensions of the index expression |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
178 and every element equal to the original scalar. For example, the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
179 following statements |
3294 | 180 |
181 @example | |
182 @group | |
183 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
184 a(ones (1, 4)) |
3294 | 185 @end group |
186 @end example | |
187 | |
188 @noindent | |
189 produce a vector whose four elements are all equal to 13. | |
190 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
191 Similarly, by indexing a scalar with two vectors of ones it is |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
192 possible to create a matrix. The following statements |
3294 | 193 |
194 @example | |
195 @group | |
196 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
197 a(ones (1, 2), ones (1, 3)) |
3294 | 198 @end group |
199 @end example | |
200 | |
201 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
202 create a 2x3 matrix with all elements equal to 13. |
3294 | 203 |
9159 | 204 The last example could also be written as |
205 | |
206 @example | |
207 @group | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
208 13(ones (2, 3)) |
9159 | 209 @end group |
210 @end example | |
211 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
212 It is more efficient to use indexing rather than the code construction |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
213 @code{scalar * ones (N, M, @dots{})} because it avoids the unnecessary |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
214 multiplication operation. Moreover, multiplication may not be |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
215 defined for the object to be replicated whereas indexing an array is |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
216 always defined. The following code shows how to create a 2x3 cell |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
217 array from a base unit which is not itself a scalar. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
218 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
219 @example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
220 @group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
221 @{"Hello"@}(ones (2, 3)) |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
222 @end group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
223 @end example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
224 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
225 It should be, noted that @code{ones (1, n)} (a row vector of ones) |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
226 results in a range (with zero increment). A range is stored |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
227 internally as a starting value, increment, end value, and total number |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
228 of values; hence, it is more efficient for storage than a vector or |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
229 matrix of ones whenever the number of elements is greater than 4. In |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
230 particular, when @samp{r} is a row vector, the expressions |
9159 | 231 |
232 @example | |
233 r(ones (1, n), :) | |
234 @end example | |
235 | |
236 @example | |
237 r(ones (n, 1), :) | |
238 @end example | |
239 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
240 @noindent |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
241 will produce identical results, but the first one will be |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
242 significantly faster, at least for @samp{r} and @samp{n} large enough. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
243 In the first case the index is held in compressed form as a range |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
244 which allows Octave to choose a more efficient algorithm to handle the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
245 expression. |
9159 | 246 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
247 A general recommendation, for a user unaware of these subtleties, is |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
248 to use the function @code{repmat} for replicating smaller arrays into |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
249 bigger ones. |
3294 | 250 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
251 A second use of indexing is to speed up code. Indexing is a fast |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
252 operation and judicious use of it can reduce the requirement for |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
253 looping over individual array elements which is a slow operation. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
254 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
255 Consider the following example which creates a 10-element row vector |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
256 @math{a} containing the values |
6642 | 257 @tex |
258 $a_i = \sqrt{i}$. | |
259 @end tex | |
260 @ifnottex | |
261 a(i) = sqrt(i). | |
262 @end ifnottex | |
263 | |
264 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
265 @group |
6642 | 266 for i = 1:10 |
267 a(i) = sqrt (i); | |
268 endfor | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
269 @end group |
6642 | 270 @end example |
271 | |
272 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
273 It is quite inefficient to create a vector using a loop like this. In |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
274 this case, it would have been much more efficient to use the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
275 expression |
3294 | 276 |
277 @example | |
278 a = sqrt (1:10); | |
279 @end example | |
280 | |
281 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
282 which avoids the loop entirely. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
283 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
284 In cases where a loop cannot be avoided, or a number of values must be |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
285 combined to form a larger matrix, it is generally faster to set the |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
286 size of the matrix first (pre-allocate storage), and then insert |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
287 elements using indexing commands. For example, given a matrix |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
288 @code{a}, |
3294 | 289 |
290 @example | |
291 @group | |
292 [nr, nc] = size (a); | |
293 x = zeros (nr, n * nc); | |
294 for i = 1:n | |
3602 | 295 x(:,(i-1)*nc+1:i*nc) = a; |
3294 | 296 endfor |
297 @end group | |
298 @end example | |
299 | |
300 @noindent | |
301 is considerably faster than | |
302 | |
303 @example | |
304 @group | |
305 x = a; | |
306 for i = 1:n-1 | |
307 x = [x, a]; | |
308 endfor | |
309 @end group | |
310 @end example | |
311 | |
312 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
313 because Octave does not have to repeatedly resize the intermediate |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
314 result. |
3294 | 315 |
6549 | 316 @DOCSTRING(sub2ind) |
317 | |
318 @DOCSTRING(ind2sub) | |
319 | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
320 @DOCSTRING(isindex) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
321 |
12544
3ba6e702e6fd
Add allow_noninteger_range_as_index to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12543
diff
changeset
|
322 @DOCSTRING(allow_noninteger_range_as_index) |
3ba6e702e6fd
Add allow_noninteger_range_as_index to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12543
diff
changeset
|
323 |
4167 | 324 @node Calling Functions |
3294 | 325 @section Calling Functions |
326 | |
327 A @dfn{function} is a name for a particular calculation. Because it has | |
328 a name, you can ask for it by name at any point in the program. For | |
329 example, the function @code{sqrt} computes the square root of a number. | |
330 | |
331 A fixed set of functions are @dfn{built-in}, which means they are | |
332 available in every Octave program. The @code{sqrt} function is one of | |
333 these. In addition, you can define your own functions. | |
334 @xref{Functions and Scripts}, for information about how to do this. | |
335 | |
336 @cindex arguments in function call | |
337 The way to use a function is with a @dfn{function call} expression, | |
338 which consists of the function name followed by a list of | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
339 @dfn{arguments} in parentheses. The arguments are expressions which give |
3294 | 340 the raw materials for the calculation that the function will do. When |
341 there is more than one argument, they are separated by commas. If there | |
342 are no arguments, you can omit the parentheses, but it is a good idea to | |
343 include them anyway, to clearly indicate that a function call was | |
344 intended. Here are some examples: | |
345 | |
346 @example | |
347 @group | |
348 sqrt (x^2 + y^2) # @r{One argument} | |
349 ones (n, m) # @r{Two arguments} | |
350 rand () # @r{No arguments} | |
351 @end group | |
352 @end example | |
353 | |
354 Each function expects a particular number of arguments. For example, the | |
355 @code{sqrt} function must be called with a single argument, the number | |
356 to take the square root of: | |
357 | |
358 @example | |
359 sqrt (@var{argument}) | |
360 @end example | |
361 | |
362 Some of the built-in functions take a variable number of arguments, | |
363 depending on the particular usage, and their behavior is different | |
364 depending on the number of arguments supplied. | |
365 | |
366 Like every other expression, the function call has a value, which is | |
367 computed by the function based on the arguments you give it. In this | |
368 example, the value of @code{sqrt (@var{argument})} is the square root of | |
369 the argument. A function can also have side effects, such as assigning | |
370 the values of certain variables or doing input or output operations. | |
371 | |
372 Unlike most languages, functions in Octave may return multiple values. | |
373 For example, the following statement | |
374 | |
375 @example | |
376 [u, s, v] = svd (a) | |
377 @end example | |
378 | |
379 @noindent | |
380 computes the singular value decomposition of the matrix @code{a} and | |
381 assigns the three result matrices to @code{u}, @code{s}, and @code{v}. | |
382 | |
383 The left side of a multiple assignment expression is itself a list of | |
384 expressions, and is allowed to be a list of variable names or index | |
385 expressions. See also @ref{Index Expressions}, and @ref{Assignment Ops}. | |
386 | |
387 @menu | |
388 * Call by Value:: | |
389 * Recursion:: | |
390 @end menu | |
391 | |
4167 | 392 @node Call by Value |
3294 | 393 @subsection Call by Value |
394 | |
395 In Octave, unlike Fortran, function arguments are passed by value, which | |
396 means that each argument in a function call is evaluated and assigned to | |
397 a temporary location in memory before being passed to the function. | |
398 There is currently no way to specify that a function parameter should be | |
399 passed by reference instead of by value. This means that it is | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8235
diff
changeset
|
400 impossible to directly alter the value of a function parameter in the |
3294 | 401 calling function. It can only change the local copy within the function |
402 body. For example, the function | |
403 | |
404 @example | |
405 @group | |
406 function f (x, n) | |
407 while (n-- > 0) | |
408 disp (x); | |
409 endwhile | |
410 endfunction | |
411 @end group | |
412 @end example | |
413 | |
414 @noindent | |
415 displays the value of the first argument @var{n} times. In this | |
416 function, the variable @var{n} is used as a temporary variable without | |
417 having to worry that its value might also change in the calling | |
418 function. Call by value is also useful because it is always possible to | |
419 pass constants for any function parameter without first having to | |
420 determine that the function will not attempt to modify the parameter. | |
421 | |
422 The caller may use a variable as the expression for the argument, but | |
423 the called function does not know this: it only knows what value the | |
424 argument had. For example, given a function called as | |
425 | |
426 @example | |
427 @group | |
428 foo = "bar"; | |
429 fcn (foo) | |
430 @end group | |
431 @end example | |
432 | |
433 @noindent | |
434 you should not think of the argument as being ``the variable | |
435 @code{foo}.'' Instead, think of the argument as the string value, | |
436 @code{"bar"}. | |
437 | |
438 Even though Octave uses pass-by-value semantics for function arguments, | |
439 values are not copied unnecessarily. For example, | |
440 | |
441 @example | |
442 @group | |
443 x = rand (1000); | |
444 f (x); | |
445 @end group | |
446 @end example | |
447 | |
448 @noindent | |
449 does not actually force two 1000 by 1000 element matrices to exist | |
450 @emph{unless} the function @code{f} modifies the value of its | |
451 argument. Then Octave must create a copy to avoid changing the | |
452 value outside the scope of the function @code{f}, or attempting (and | |
453 probably failing!) to modify the value of a constant or the value of a | |
454 temporary result. | |
455 | |
4167 | 456 @node Recursion |
3294 | 457 @subsection Recursion |
458 @cindex factorial function | |
459 | |
6939 | 460 With some restrictions@footnote{Some of Octave's functions are |
3294 | 461 implemented in terms of functions that cannot be called recursively. |
462 For example, the ODE solver @code{lsode} is ultimately implemented in a | |
463 Fortran subroutine that cannot be called recursively, so @code{lsode} | |
464 should not be called either directly or indirectly from within the | |
465 user-supplied function that @code{lsode} requires. Doing so will result | |
6642 | 466 in an error.}, recursive function calls are allowed. A |
3294 | 467 @dfn{recursive function} is one which calls itself, either directly or |
468 indirectly. For example, here is an inefficient@footnote{It would be | |
469 much better to use @code{prod (1:n)}, or @code{gamma (n+1)} instead, | |
470 after first checking to ensure that the value @code{n} is actually a | |
471 positive integer.} way to compute the factorial of a given integer: | |
472 | |
473 @example | |
474 @group | |
475 function retval = fact (n) | |
476 if (n > 0) | |
477 retval = n * fact (n-1); | |
478 else | |
479 retval = 1; | |
480 endif | |
481 endfunction | |
482 @end group | |
483 @end example | |
484 | |
485 This function is recursive because it calls itself directly. It | |
486 eventually terminates because each time it calls itself, it uses an | |
487 argument that is one less than was used for the previous call. Once the | |
488 argument is no longer greater than zero, it does not call itself, and | |
489 the recursion ends. | |
490 | |
491 The built-in variable @code{max_recursion_depth} specifies a limit to | |
492 the recursion depth and prevents Octave from recursing infinitely. | |
493 | |
3371 | 494 @DOCSTRING(max_recursion_depth) |
3294 | 495 |
4167 | 496 @node Arithmetic Ops |
3294 | 497 @section Arithmetic Operators |
498 @cindex arithmetic operators | |
499 @cindex operators, arithmetic | |
500 @cindex addition | |
501 @cindex subtraction | |
502 @cindex multiplication | |
503 @cindex matrix multiplication | |
504 @cindex division | |
505 @cindex quotient | |
506 @cindex negation | |
507 @cindex unary minus | |
508 @cindex exponentiation | |
509 @cindex transpose | |
510 @cindex Hermitian operator | |
511 @cindex transpose, complex-conjugate | |
512 @cindex complex-conjugate transpose | |
513 | |
514 The following arithmetic operators are available, and work on scalars | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
515 and matrices. The element-by-element operators and functions broadcast |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
516 (@pxref{Broadcasting}). |
3294 | 517 |
13780
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
12627
diff
changeset
|
518 @table @asis |
3294 | 519 @item @var{x} + @var{y} |
520 @opindex + | |
521 Addition. If both operands are matrices, the number of rows and columns | |
522 must both agree. If one operand is a scalar, its value is added to | |
523 all the elements of the other operand. | |
524 | |
525 @item @var{x} .+ @var{y} | |
526 @opindex .+ | |
527 Element by element addition. This operator is equivalent to @code{+}. | |
528 | |
529 @item @var{x} - @var{y} | |
530 @opindex - | |
531 Subtraction. If both operands are matrices, the number of rows and | |
532 columns of both must agree. | |
533 | |
534 @item @var{x} .- @var{y} | |
535 Element by element subtraction. This operator is equivalent to @code{-}. | |
536 | |
537 @item @var{x} * @var{y} | |
538 @opindex * | |
539 Matrix multiplication. The number of columns of @var{x} must agree | |
540 with the number of rows of @var{y}. | |
541 | |
542 @item @var{x} .* @var{y} | |
543 @opindex .* | |
544 Element by element multiplication. If both operands are matrices, the | |
545 number of rows and columns must both agree. | |
546 | |
547 @item @var{x} / @var{y} | |
548 @opindex / | |
549 Right division. This is conceptually equivalent to the expression | |
550 | |
551 @example | |
552 (inverse (y') * x')' | |
553 @end example | |
554 | |
555 @noindent | |
556 but it is computed without forming the inverse of @var{y'}. | |
557 | |
558 If the system is not square, or if the coefficient matrix is singular, | |
559 a minimum norm solution is computed. | |
560 | |
561 @item @var{x} ./ @var{y} | |
562 @opindex ./ | |
563 Element by element right division. | |
564 | |
565 @item @var{x} \ @var{y} | |
566 @opindex \ | |
567 Left division. This is conceptually equivalent to the expression | |
568 | |
569 @example | |
570 inverse (x) * y | |
571 @end example | |
572 | |
573 @noindent | |
574 but it is computed without forming the inverse of @var{x}. | |
575 | |
576 If the system is not square, or if the coefficient matrix is singular, | |
577 a minimum norm solution is computed. | |
578 | |
579 @item @var{x} .\ @var{y} | |
580 @opindex .\ | |
581 Element by element left division. Each element of @var{y} is divided | |
582 by each corresponding element of @var{x}. | |
583 | |
584 @item @var{x} ^ @var{y} | |
585 @itemx @var{x} ** @var{y} | |
586 @opindex ** | |
587 @opindex ^ | |
588 Power operator. If @var{x} and @var{y} are both scalars, this operator | |
589 returns @var{x} raised to the power @var{y}. If @var{x} is a scalar and | |
590 @var{y} is a square matrix, the result is computed using an eigenvalue | |
7001 | 591 expansion. If @var{x} is a square matrix, the result is computed by |
3294 | 592 repeated multiplication if @var{y} is an integer, and by an eigenvalue |
593 expansion if @var{y} is not an integer. An error results if both | |
594 @var{x} and @var{y} are matrices. | |
595 | |
596 The implementation of this operator needs to be improved. | |
597 | |
598 @item @var{x} .^ @var{y} | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
599 @itemx @var{x} .** @var{y} |
3294 | 600 @opindex .** |
601 @opindex .^ | |
602 Element by element power operator. If both operands are matrices, the | |
603 number of rows and columns must both agree. | |
604 | |
605 @item -@var{x} | |
606 @opindex - | |
607 Negation. | |
608 | |
609 @item +@var{x} | |
610 @opindex + | |
611 Unary plus. This operator has no effect on the operand. | |
612 | |
613 @item @var{x}' | |
614 @opindex ' | |
615 Complex conjugate transpose. For real arguments, this operator is the | |
616 same as the transpose operator. For complex arguments, this operator is | |
617 equivalent to the expression | |
618 | |
619 @example | |
620 conj (x.') | |
621 @end example | |
622 | |
623 @item @var{x}.' | |
624 @opindex .' | |
625 Transpose. | |
626 @end table | |
627 | |
628 Note that because Octave's element by element operators begin with a | |
629 @samp{.}, there is a possible ambiguity for statements like | |
630 | |
631 @example | |
632 1./m | |
633 @end example | |
634 | |
635 @noindent | |
636 because the period could be interpreted either as part of the constant | |
637 or as part of the operator. To resolve this conflict, Octave treats the | |
638 expression as if you had typed | |
639 | |
640 @example | |
641 (1) ./ m | |
642 @end example | |
643 | |
644 @noindent | |
645 and not | |
646 | |
647 @example | |
648 (1.) / m | |
649 @end example | |
650 | |
651 @noindent | |
652 Although this is inconsistent with the normal behavior of Octave's | |
653 lexer, which usually prefers to break the input into tokens by | |
654 preferring the longest possible match at any given point, it is more | |
655 useful in this case. | |
656 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
657 @opindex ' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
658 @DOCSTRING(ctranspose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
659 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
660 @opindex .\ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
661 @DOCSTRING(ldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
662 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
663 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
664 @DOCSTRING(minus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
665 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
666 @opindex \ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
667 @DOCSTRING(mldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
668 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
669 @opindex ** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
670 @opindex ^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
671 @DOCSTRING(mpower) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
672 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
673 @opindex / |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
674 @DOCSTRING(mrdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
675 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
676 @opindex * |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
677 @DOCSTRING(mtimes) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
678 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
679 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
680 @DOCSTRING(plus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
681 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
682 @opindex .** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
683 @opindex .^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
684 @DOCSTRING(power) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
685 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
686 @opindex ./ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
687 @DOCSTRING(rdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
688 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
689 @opindex .* |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
690 @DOCSTRING(times) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
691 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
692 @opindex .' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
693 @DOCSTRING(transpose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
694 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
695 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
696 @DOCSTRING(uminus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
697 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
698 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
699 @DOCSTRING(uplus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
700 |
4167 | 701 @node Comparison Ops |
3294 | 702 @section Comparison Operators |
703 @cindex comparison expressions | |
704 @cindex expressions, comparison | |
705 @cindex relational operators | |
706 @cindex operators, relational | |
707 @cindex less than operator | |
708 @cindex greater than operator | |
709 @cindex equality operator | |
710 @cindex tests for equality | |
711 @cindex equality, tests for | |
712 | |
713 @dfn{Comparison operators} compare numeric values for relationships | |
714 such as equality. They are written using | |
715 @emph{relational operators}. | |
716 | |
717 All of Octave's comparison operators return a value of 1 if the | |
718 comparison is true, or 0 if it is false. For matrix values, they all | |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
719 work on an element-by-element basis. Broadcasting rules apply. |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
720 @xref{Broadcasting}. For example: |
3294 | 721 |
722 @example | |
723 @group | |
724 [1, 2; 3, 4] == [1, 3; 2, 4] | |
725 @result{} 1 0 | |
726 0 1 | |
727 @end group | |
728 @end example | |
729 | |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
730 According to broadcasting rules, if one operand is a scalar and the |
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
731 other is a matrix, the scalar is compared to each element of the matrix |
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
732 in turn, and the result is the same size as the matrix. |
3294 | 733 |
734 @table @code | |
735 @item @var{x} < @var{y} | |
736 @opindex < | |
737 True if @var{x} is less than @var{y}. | |
738 | |
739 @item @var{x} <= @var{y} | |
740 @opindex <= | |
741 True if @var{x} is less than or equal to @var{y}. | |
742 | |
743 @item @var{x} == @var{y} | |
744 @opindex == | |
745 True if @var{x} is equal to @var{y}. | |
746 | |
747 @item @var{x} >= @var{y} | |
748 @opindex >= | |
749 True if @var{x} is greater than or equal to @var{y}. | |
750 | |
751 @item @var{x} > @var{y} | |
752 @opindex > | |
753 True if @var{x} is greater than @var{y}. | |
754 | |
755 @item @var{x} != @var{y} | |
756 @itemx @var{x} ~= @var{y} | |
757 @opindex != | |
758 @opindex ~= | |
759 True if @var{x} is not equal to @var{y}. | |
760 @end table | |
761 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
762 For complex numbers, the following ordering is defined: |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
763 @var{z1} < @var{z2} |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
764 iff |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
765 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
766 @example |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9578
diff
changeset
|
767 @group |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
768 abs(@var{z1}) < abs(@var{z2}) |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
769 || (abs(@var{z1}) == abs(@var{z2}) && arg(@var{z1}) < arg(@var{z2})) |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9578
diff
changeset
|
770 @end group |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
771 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
772 |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
773 This is consistent with the ordering used by @dfn{max}, @dfn{min} and |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
774 @dfn{sort}, but is not consistent with @sc{matlab}, which only compares the real |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
775 parts. |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
776 |
3294 | 777 String comparisons may also be performed with the @code{strcmp} |
778 function, not with the comparison operators listed above. | |
779 @xref{Strings}. | |
780 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
781 @opindex == |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
782 @DOCSTRING(eq) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
783 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
784 @opindex >= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
785 @DOCSTRING(ge) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
786 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
787 @opindex > |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
788 @DOCSTRING(gt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
789 |
6550 | 790 @DOCSTRING(isequal) |
791 | |
792 @DOCSTRING(isequalwithequalnans) | |
793 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
794 @opindex <= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
795 @DOCSTRING(le) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
796 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
797 @opindex < |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
798 @DOCSTRING(lt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
799 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
800 @opindex != |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
801 @opindex ~= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
802 @DOCSTRING(ne) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
803 |
4167 | 804 @node Boolean Expressions |
3294 | 805 @section Boolean Expressions |
806 @cindex expressions, boolean | |
807 @cindex boolean expressions | |
808 @cindex expressions, logical | |
809 @cindex logical expressions | |
810 @cindex operators, boolean | |
811 @cindex boolean operators | |
812 @cindex logical operators | |
813 @cindex operators, logical | |
814 @cindex and operator | |
815 @cindex or operator | |
816 @cindex not operator | |
817 | |
818 @menu | |
819 * Element-by-element Boolean Operators:: | |
820 * Short-circuit Boolean Operators:: | |
821 @end menu | |
822 | |
4167 | 823 @node Element-by-element Boolean Operators |
3294 | 824 @subsection Element-by-element Boolean Operators |
825 @cindex element-by-element evaluation | |
826 | |
827 An @dfn{element-by-element boolean expression} is a combination of | |
828 comparison expressions using the boolean | |
829 operators ``or'' (@samp{|}), ``and'' (@samp{&}), and ``not'' (@samp{!}), | |
830 along with parentheses to control nesting. The truth of the boolean | |
831 expression is computed by combining the truth values of the | |
832 corresponding elements of the component expressions. A value is | |
833 considered to be false if it is zero, and true otherwise. | |
834 | |
835 Element-by-element boolean expressions can be used wherever comparison | |
836 expressions can be used. They can be used in @code{if} and @code{while} | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
837 statements. However, a matrix value used as the condition in an |
3294 | 838 @code{if} or @code{while} statement is only true if @emph{all} of its |
839 elements are nonzero. | |
840 | |
841 Like comparison operations, each element of an element-by-element | |
842 boolean expression also has a numeric value (1 if true, 0 if false) that | |
843 comes into play if the result of the boolean expression is stored in a | |
844 variable, or used in arithmetic. | |
845 | |
846 Here are descriptions of the three element-by-element boolean operators. | |
847 | |
848 @table @code | |
849 @item @var{boolean1} & @var{boolean2} | |
850 @opindex & | |
851 Elements of the result are true if both corresponding elements of | |
852 @var{boolean1} and @var{boolean2} are true. | |
853 | |
854 @item @var{boolean1} | @var{boolean2} | |
855 @opindex | | |
856 Elements of the result are true if either of the corresponding elements | |
857 of @var{boolean1} or @var{boolean2} is true. | |
858 | |
859 @item ! @var{boolean} | |
860 @itemx ~ @var{boolean} | |
861 @opindex ~ | |
862 @opindex ! | |
863 Each element of the result is true if the corresponding element of | |
864 @var{boolean} is false. | |
865 @end table | |
866 | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
867 These operators work on an element-by-element basis. For example, the |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
868 expression |
3294 | 869 |
870 @example | |
871 [1, 0; 0, 1] & [1, 0; 2, 3] | |
872 @end example | |
873 | |
874 @noindent | |
875 returns a two by two identity matrix. | |
876 | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
877 For the binary operators, broadcasting rules apply. @xref{Broadcasting}. |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
878 In particular, if one of the operands is a scalar and the other a |
3294 | 879 matrix, the operator is applied to the scalar and each element of the |
880 matrix. | |
881 | |
882 For the binary element-by-element boolean operators, both subexpressions | |
883 @var{boolean1} and @var{boolean2} are evaluated before computing the | |
884 result. This can make a difference when the expressions have side | |
885 effects. For example, in the expression | |
886 | |
887 @example | |
888 a & b++ | |
889 @end example | |
890 | |
891 @noindent | |
892 the value of the variable @var{b} is incremented even if the variable | |
893 @var{a} is zero. | |
894 | |
895 This behavior is necessary for the boolean operators to work as | |
896 described for matrix-valued operands. | |
897 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
898 @opindex & |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
899 @DOCSTRING(and) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
900 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
901 @opindex ~ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
902 @opindex ! |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
903 @DOCSTRING(not) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
904 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
905 @opindex | |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
906 @DOCSTRING(or) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
907 |
4167 | 908 @node Short-circuit Boolean Operators |
3294 | 909 @subsection Short-circuit Boolean Operators |
910 @cindex short-circuit evaluation | |
911 | |
912 Combined with the implicit conversion to scalar values in @code{if} and | |
913 @code{while} conditions, Octave's element-by-element boolean operators | |
914 are often sufficient for performing most logical operations. However, | |
915 it is sometimes desirable to stop evaluating a boolean expression as | |
916 soon as the overall truth value can be determined. Octave's | |
917 @dfn{short-circuit} boolean operators work this way. | |
918 | |
919 @table @code | |
920 @item @var{boolean1} && @var{boolean2} | |
921 @opindex && | |
922 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 923 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 924 If it is false, the result of the overall expression is 0. If it is |
925 true, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 926 scalar using the equivalent of the operation @code{all |
927 (@var{boolean1}(:))}. If it is true, the result of the overall expression | |
3294 | 928 is 1. Otherwise, the result of the overall expression is 0. |
929 | |
6632 | 930 @strong{Warning:} there is one exception to the rule of evaluating |
931 @code{all (@var{boolean1}(:))}, which is when @code{boolean1} is the | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
932 empty matrix. The truth value of an empty matrix is always @code{false} |
6632 | 933 so @code{[] && true} evaluates to @code{false} even though |
934 @code{all ([])} is @code{true}. | |
935 | |
3294 | 936 @item @var{boolean1} || @var{boolean2} |
937 @opindex || | |
938 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 939 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 940 If it is true, the result of the overall expression is 1. If it is |
941 false, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 942 scalar using the equivalent of the operation @code{all |
943 (@var{boolean1}(:))}. If it is true, the result of the overall expression | |
3294 | 944 is 1. Otherwise, the result of the overall expression is 0. |
6632 | 945 |
946 @strong{Warning:} the truth value of an empty matrix is always @code{false}, | |
947 see the previous list item for details. | |
3294 | 948 @end table |
949 | |
950 The fact that both operands may not be evaluated before determining the | |
951 overall truth value of the expression can be important. For example, in | |
952 the expression | |
953 | |
954 @example | |
955 a && b++ | |
956 @end example | |
957 | |
958 @noindent | |
959 the value of the variable @var{b} is only incremented if the variable | |
960 @var{a} is nonzero. | |
961 | |
962 This can be used to write somewhat more concise code. For example, it | |
963 is possible write | |
964 | |
965 @example | |
966 @group | |
967 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
968 if (nargin > 2 && ischar (c)) |
3294 | 969 @dots{} |
970 @end group | |
971 @end example | |
972 | |
973 @noindent | |
974 instead of having to use two @code{if} statements to avoid attempting to | |
975 evaluate an argument that doesn't exist. For example, without the | |
976 short-circuit feature, it would be necessary to write | |
977 | |
978 @example | |
979 @group | |
980 function f (a, b, c) | |
981 if (nargin > 2) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
982 if (ischar (c)) |
3294 | 983 @dots{} |
984 @end group | |
985 @end example | |
986 | |
6632 | 987 @noindent |
3294 | 988 Writing |
989 | |
990 @example | |
991 @group | |
992 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
993 if (nargin > 2 & ischar (c)) |
3294 | 994 @dots{} |
995 @end group | |
996 @end example | |
997 | |
998 @noindent | |
999 would result in an error if @code{f} were called with one or two | |
1000 arguments because Octave would be forced to try to evaluate both of the | |
1001 operands for the operator @samp{&}. | |
1002 | |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1003 @sc{matlab} has special behavior that allows the operators @samp{&} and |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1004 @samp{|} to short-circuit when used in the truth expression for @code{if} and |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1005 @code{while} statements. The Octave parser may be instructed to behave in the |
12601
99babbf683ff
doc: Correct use of it's -> its in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1006 same manner, but its use is strongly discouraged. |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1007 |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1008 @DOCSTRING(do_braindead_shortcircuit_evaluation) |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1009 |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1010 Finally, the ternary operator (?:) is not supported in Octave. If |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1011 short-circuiting is not important, it can be replaced by the @code{ifelse} |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1012 function. |
10308 | 1013 |
11552
6b6e9051ecb8
Add merge/ifelse function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1014 @DOCSTRING(merge) |
10308 | 1015 |
4167 | 1016 @node Assignment Ops |
3294 | 1017 @section Assignment Expressions |
1018 @cindex assignment expressions | |
1019 @cindex assignment operators | |
1020 @cindex operators, assignment | |
1021 @cindex expressions, assignment | |
1022 | |
1023 @opindex = | |
1024 | |
1025 An @dfn{assignment} is an expression that stores a new value into a | |
1026 variable. For example, the following expression assigns the value 1 to | |
1027 the variable @code{z}: | |
1028 | |
1029 @example | |
1030 z = 1 | |
1031 @end example | |
1032 | |
6632 | 1033 @noindent |
3294 | 1034 After this expression is executed, the variable @code{z} has the value 1. |
1035 Whatever old value @code{z} had before the assignment is forgotten. | |
1036 The @samp{=} sign is called an @dfn{assignment operator}. | |
1037 | |
1038 Assignments can store string values also. For example, the following | |
1039 expression would store the value @code{"this food is good"} in the | |
1040 variable @code{message}: | |
1041 | |
1042 @example | |
1043 @group | |
1044 thing = "food" | |
1045 predicate = "good" | |
1046 message = [ "this " , thing , " is " , predicate ] | |
1047 @end group | |
1048 @end example | |
1049 | |
1050 @noindent | |
1051 (This also illustrates concatenation of strings.) | |
1052 | |
1053 @cindex side effect | |
1054 Most operators (addition, concatenation, and so on) have no effect | |
1055 except to compute a value. If you ignore the value, you might as well | |
1056 not use the operator. An assignment operator is different. It does | |
1057 produce a value, but even if you ignore the value, the assignment still | |
1058 makes itself felt through the alteration of the variable. We call this | |
1059 a @dfn{side effect}. | |
1060 | |
1061 @cindex lvalue | |
1062 The left-hand operand of an assignment need not be a variable | |
1063 (@pxref{Variables}). It can also be an element of a matrix | |
1064 (@pxref{Index Expressions}) or a list of return values | |
1065 (@pxref{Calling Functions}). These are all called @dfn{lvalues}, which | |
1066 means they can appear on the left-hand side of an assignment operator. | |
1067 The right-hand operand may be any expression. It produces the new value | |
1068 which the assignment stores in the specified variable, matrix element, | |
1069 or list of return values. | |
1070 | |
1071 It is important to note that variables do @emph{not} have permanent types. | |
1072 The type of a variable is simply the type of whatever value it happens | |
1073 to hold at the moment. In the following program fragment, the variable | |
1074 @code{foo} has a numeric value at first, and a string value later on: | |
1075 | |
1076 @example | |
1077 @group | |
1078 octave:13> foo = 1 | |
1079 foo = 1 | |
1080 octave:13> foo = "bar" | |
1081 foo = bar | |
1082 @end group | |
1083 @end example | |
1084 | |
1085 @noindent | |
1086 When the second assignment gives @code{foo} a string value, the fact that | |
1087 it previously had a numeric value is forgotten. | |
1088 | |
1089 Assignment of a scalar to an indexed matrix sets all of the elements | |
1090 that are referenced by the indices to the scalar value. For example, if | |
1091 @code{a} is a matrix with at least two columns, | |
1092 | |
1093 @example | |
1094 @group | |
1095 a(:, 2) = 5 | |
1096 @end group | |
1097 @end example | |
1098 | |
1099 @noindent | |
1100 sets all the elements in the second column of @code{a} to 5. | |
1101 | |
1102 Assigning an empty matrix @samp{[]} works in most cases to allow you to | |
1103 delete rows or columns of matrices and vectors. @xref{Empty Matrices}. | |
1104 For example, given a 4 by 5 matrix @var{A}, the assignment | |
1105 | |
1106 @example | |
1107 A (3, :) = [] | |
1108 @end example | |
1109 | |
1110 @noindent | |
1111 deletes the third row of @var{A}, and the assignment | |
1112 | |
1113 @example | |
1114 A (:, 1:2:5) = [] | |
1115 @end example | |
1116 | |
1117 @noindent | |
6672 | 1118 deletes the first, third, and fifth columns. |
3294 | 1119 |
1120 An assignment is an expression, so it has a value. Thus, @code{z = 1} | |
1121 as an expression has the value 1. One consequence of this is that you | |
1122 can write multiple assignments together: | |
1123 | |
1124 @example | |
1125 x = y = z = 0 | |
1126 @end example | |
1127 | |
1128 @noindent | |
1129 stores the value 0 in all three variables. It does this because the | |
1130 value of @code{z = 0}, which is 0, is stored into @code{y}, and then | |
1131 the value of @code{y = z = 0}, which is 0, is stored into @code{x}. | |
1132 | |
1133 This is also true of assignments to lists of values, so the following is | |
1134 a valid expression | |
1135 | |
1136 @example | |
1137 [a, b, c] = [u, s, v] = svd (a) | |
1138 @end example | |
1139 | |
1140 @noindent | |
1141 that is exactly equivalent to | |
1142 | |
1143 @example | |
1144 @group | |
1145 [u, s, v] = svd (a) | |
1146 a = u | |
1147 b = s | |
1148 c = v | |
1149 @end group | |
1150 @end example | |
1151 | |
1152 In expressions like this, the number of values in each part of the | |
1153 expression need not match. For example, the expression | |
1154 | |
1155 @example | |
1156 [a, b] = [u, s, v] = svd (a) | |
1157 @end example | |
1158 | |
1159 @noindent | |
1160 is equivalent to | |
1161 | |
1162 @example | |
1163 @group | |
1164 [u, s, v] = svd (a) | |
1165 a = u | |
1166 b = s | |
1167 @end group | |
1168 @end example | |
1169 | |
6632 | 1170 @noindent |
1171 The number of values on the left side of the expression can, however, | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1172 not exceed the number of values on the right side. For example, the |
6632 | 1173 following will produce an error. |
1174 | |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1175 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
1176 @group |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7768
diff
changeset
|
1177 [a, b, c, d] = [u, s, v] = svd (a); |
7031 | 1178 @print{} error: element number 4 undefined in return list |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
1179 @end group |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1180 @end example |
6632 | 1181 |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1182 The symbol @code{~} may be used as a placeholder in the list of lvalues, |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1183 indicating that the corresponding return value should be ignored and not stored |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1184 anywhere: |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1185 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1186 @example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1187 @group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1188 [~, s, v] = svd (a); |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1189 @end group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1190 @end example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1191 |
10228 | 1192 This is cleaner and more memory efficient than using a dummy variable. |
1193 The @code{nargout} value for the right-hand side expression is not affected. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
1194 If the assignment is used as an expression, the return value is a |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
1195 comma-separated list with the ignored values dropped. |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1196 |
6642 | 1197 @opindex += |
1198 A very common programming pattern is to increment an existing variable | |
1199 with a given value, like this | |
1200 | |
1201 @example | |
1202 a = a + 2; | |
1203 @end example | |
1204 | |
1205 @noindent | |
1206 This can be written in a clearer and more condensed form using the | |
1207 @code{+=} operator | |
1208 | |
1209 @example | |
1210 a += 2; | |
1211 @end example | |
1212 | |
1213 @noindent | |
1214 @opindex -= | |
1215 @opindex *= | |
1216 @opindex /= | |
1217 Similar operators also exist for subtraction (@code{-=}), | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1218 multiplication (@code{*=}), and division (@code{/=}). An expression |
6642 | 1219 of the form |
1220 | |
1221 @example | |
1222 @var{expr1} @var{op}= @var{expr2} | |
1223 @end example | |
1224 | |
1225 @noindent | |
1226 is evaluated as | |
1227 | |
1228 @example | |
1229 @var{expr1} = (@var{expr1}) @var{op} (@var{expr2}) | |
1230 @end example | |
1231 | |
1232 @noindent | |
1233 where @var{op} can be either @code{+}, @code{-}, @code{*}, or @code{/}. | |
1234 So, the expression | |
1235 | |
1236 @example | |
1237 a *= b+1 | |
1238 @end example | |
1239 | |
1240 @noindent | |
1241 is evaluated as | |
1242 | |
1243 @example | |
1244 a = a * (b+1) | |
1245 @end example | |
1246 | |
1247 @noindent | |
1248 and @emph{not} | |
1249 | |
1250 @example | |
1251 a = a * b + 1 | |
1252 @end example | |
1253 | |
3294 | 1254 You can use an assignment anywhere an expression is called for. For |
1255 example, it is valid to write @code{x != (y = 1)} to set @code{y} to 1 | |
1256 and then test whether @code{x} equals 1. But this style tends to make | |
1257 programs hard to read. Except in a one-shot program, you should rewrite | |
1258 it to get rid of such nesting of assignments. This is never very hard. | |
1259 | |
1260 @cindex increment operator | |
1261 @cindex decrement operator | |
1262 @cindex operators, increment | |
1263 @cindex operators, decrement | |
1264 | |
4167 | 1265 @node Increment Ops |
3294 | 1266 @section Increment Operators |
1267 | |
1268 @emph{Increment operators} increase or decrease the value of a variable | |
1269 by 1. The operator to increment a variable is written as @samp{++}. It | |
1270 may be used to increment a variable either before or after taking its | |
1271 value. | |
1272 | |
1273 For example, to pre-increment the variable @var{x}, you would write | |
1274 @code{++@var{x}}. This would add one to @var{x} and then return the new | |
1275 value of @var{x} as the result of the expression. It is exactly the | |
1276 same as the expression @code{@var{x} = @var{x} + 1}. | |
1277 | |
1278 To post-increment a variable @var{x}, you would write @code{@var{x}++}. | |
1279 This adds one to the variable @var{x}, but returns the value that | |
1280 @var{x} had prior to incrementing it. For example, if @var{x} is equal | |
1281 to 2, the result of the expression @code{@var{x}++} is 2, and the new | |
1282 value of @var{x} is 3. | |
1283 | |
1284 For matrix and vector arguments, the increment and decrement operators | |
1285 work on each element of the operand. | |
1286 | |
1287 Here is a list of all the increment and decrement expressions. | |
1288 | |
1289 @table @code | |
1290 @item ++@var{x} | |
1291 @opindex ++ | |
1292 This expression increments the variable @var{x}. The value of the | |
1293 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1294 expression @code{@var{x} = @var{x} + 1}. | |
1295 | |
1296 @item --@var{x} | |
1297 @opindex @code{--} | |
1298 This expression decrements the variable @var{x}. The value of the | |
1299 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1300 expression @code{@var{x} = @var{x} - 1}. | |
1301 | |
1302 @item @var{x}++ | |
1303 @opindex ++ | |
1304 This expression causes the variable @var{x} to be incremented. The | |
1305 value of the expression is the @emph{old} value of @var{x}. | |
1306 | |
1307 @item @var{x}-- | |
1308 @opindex @code{--} | |
1309 This expression causes the variable @var{x} to be decremented. The | |
1310 value of the expression is the @emph{old} value of @var{x}. | |
1311 @end table | |
1312 | |
4167 | 1313 @node Operator Precedence |
3294 | 1314 @section Operator Precedence |
1315 @cindex operator precedence | |
1316 | |
1317 @dfn{Operator precedence} determines how operators are grouped, when | |
1318 different operators appear close by in one expression. For example, | |
1319 @samp{*} has higher precedence than @samp{+}. Thus, the expression | |
1320 @code{a + b * c} means to multiply @code{b} and @code{c}, and then add | |
1321 @code{a} to the product (i.e., @code{a + (b * c)}). | |
1322 | |
1323 You can overrule the precedence of the operators by using parentheses. | |
1324 You can think of the precedence rules as saying where the parentheses | |
1325 are assumed if you do not write parentheses yourself. In fact, it is | |
1326 wise to use parentheses whenever you have an unusual combination of | |
1327 operators, because other people who read the program may not remember | |
1328 what the precedence is in this case. You might forget as well, and then | |
1329 you too could make a mistake. Explicit parentheses will help prevent | |
1330 any such mistake. | |
1331 | |
1332 When operators of equal precedence are used together, the leftmost | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1333 operator groups first, except for the assignment operators, which group |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1334 in the opposite order. Thus, the expression @code{a - b + c} groups as |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1335 @code{(a - b) + c}, but the expression @code{a = b = c} groups as |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1336 @code{a = (b = c)}. |
3294 | 1337 |
1338 The precedence of prefix unary operators is important when another | |
1339 operator follows the operand. For example, @code{-x^2} means | |
1340 @code{-(x^2)}, because @samp{-} has lower precedence than @samp{^}. | |
1341 | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1342 Here is a table of the operators in Octave, in order of decreasing |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1343 precedence. Unless noted, all operators group left to right. |
3294 | 1344 |
1345 @table @code | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1346 @item function call and array indexing, cell array indexing, and structure element indexing |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1347 @samp{()} @samp{@{@}} @samp{.} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1348 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1349 @item postfix increment, and postfix decrement |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1350 @samp{++} @samp{--} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1351 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1352 These operators group right to left. |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1353 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1354 @item transpose and exponentiation |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1355 @samp{'} @samp{.'} @samp{^} @samp{**} @samp{.^} @samp{.**} |
3294 | 1356 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1357 @item unary plus, unary minus, prefix increment, prefix decrement, and logical "not" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1358 @samp{+} @samp{-} @samp{++} @samp{--} @samp{~} @samp{!} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1359 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1360 @item multiply and divide |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1361 @samp{*} @samp{/} @samp{\} @samp{.\} @samp{.*} @samp{./} |
3294 | 1362 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1363 @item add, subtract |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1364 @samp{+} @samp{-} |
3294 | 1365 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1366 @item colon |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1367 @samp{:} |
3294 | 1368 |
1369 @item relational | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1370 @samp{<} @samp{<=} @samp{==} @samp{>=} @samp{>} @samp{!=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1371 @samp{~=} |
3294 | 1372 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1373 @item element-wise "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1374 @samp{&} |
3294 | 1375 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1376 @item element-wise "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1377 @samp{|} |
3294 | 1378 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1379 @item logical "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1380 @samp{&&} |
3294 | 1381 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1382 @item logical "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1383 @samp{||} |
3294 | 1384 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1385 @item assignment |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1386 @samp{=} @samp{+=} @samp{-=} @samp{*=} @samp{/=} @samp{\=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1387 @samp{^=} @samp{.*=} @samp{./=} @samp{.\=} @samp{.^=} @samp{|=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1388 @samp{&=} |
3294 | 1389 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1390 These operators group right to left. |
3294 | 1391 @end table |