Mercurial > jwe > octave
annotate doc/interpreter/expr.txi @ 24510:a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
expr.txi: Add sub-node "Access via Handle" to the "Calling Functions" node.
Don't indent a paragraph that refers to the previous example. Provide the
body for the "Access via Handle" node and include an '@' opindex entry
qualified by "function handle". Mention that '@' is also used for class
methods and reference the "Object Oriented Programming" chapter.
oop.txi: Add an opindex reference to '@' qualified by "class methods" so a
quick index link is created.
op-kw-docs: Create an operator index entry for '@'. Mention that '@' is also
used for class methods and suggest seeing the "Object Oriented Programming"
chapter of the manual.
octave.texi: Add sub-node "Access via Handle" to sub-menu list.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Tue, 02 Jan 2018 15:29:10 -0600 |
parents | dc25a0dc7800 |
children | 194eb4bd202b |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1 @c Copyright (C) 1996-2017 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
6 @c under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
7 @c the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
8 @c (at your option) any later version. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
9 @c |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
10 @c Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
11 @c WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
12 @c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22620
diff
changeset
|
13 @c GNU General Public License for more details. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
14 @c |
7018 | 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 | |
17152
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
35 * Index Expressions:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
36 * Calling Functions:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
37 * Arithmetic Ops:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
38 * Comparison Ops:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
39 * Boolean Expressions:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
40 * Assignment Ops:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
41 * Increment Ops:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
42 * Operator Precedence:: |
3294 | 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 |
24507
dc25a0dc7800
Correct a host of small formatting issues with Texinfo manual (bug #52774)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24469
diff
changeset
|
109 @cindex @sortas{end:} @code{end:} and @code{:end} |
14033
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] |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
122 a(end + 1) = 5; # append element |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
123 a(end) = []; # delete element |
14033
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 |
24468
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
137 An array with @samp{nd} dimensions can be indexed by a vector @var{idx} which |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
138 has from 1 to @samp{nd} elements. If any element of @var{idx} is not a |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
139 scalar then the complete set of index tuples will be generated from the |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
140 Cartesian product of the index elements. |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
141 |
24468
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
142 For the ordinary and most common case, the number of indices |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
143 (@code{nidx = numel (@var{idx})}) matches the number of dimensions @samp{nd}. |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
144 In this case, each element of @var{idx} corresponds to its respective dimension, |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
145 i.e., @code{@var{idx}(1)} refers to dimension 1, @code{@var{idx}(2)} refers to |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
146 dimension 2, etc. If @w{@code{nidx < nd}}, and every index is less than the |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
147 size of the array in the @math{i^{th}} dimension |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
148 (@code{@var{idx}(i) < size (@var{array}, i)}), then the index expression is |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
149 padded with @w{@code{nd - nidx}} trailing singleton dimensions. If |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
150 @w{@code{nidx < nd}} but one of the indices @code{@var{idx}(i)} is outside the |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
151 size of the current array, then the last @w{@code{nd - nidx + 1}} dimensions |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
152 are folded into a single dimension with an extent equal to the product of |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
153 extents of the original dimensions. This is easiest to understand with an |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
154 example. |
3294 | 155 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
156 @example |
24468
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
157 A = reshape (1:8, 2, 2, 2) # Create 3-D array |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
158 A = |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
159 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
160 ans(:,:,1) = |
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 1 3 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
163 2 4 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
164 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
165 ans(:,:,2) = |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
166 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
167 5 7 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
168 6 8 |
9159 | 169 |
24468
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
170 A(2,1,2); # Case (nidx == nd): ans = 6 |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
171 A(2,1); # Case (nidx < nd), idx within array: |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
172 # equivalent to A(2,1,1), ans = 2 |
abe0b0e08897
doc: Rewrite documentation for Advanced Indexing (bug #52723).
Rik <rik@octave.org>
parents:
24454
diff
changeset
|
173 A(2,4); # Case (nidx < nd), idx outside array: |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
174 # 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
|
175 # 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
|
176 @end example |
3294 | 177 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 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
|
182 following statements |
3294 | 183 |
184 @example | |
185 @group | |
186 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
187 a(ones (1, 4)) |
3294 | 188 @end group |
189 @end example | |
190 | |
191 @noindent | |
192 produce a vector whose four elements are all equal to 13. | |
193 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
194 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
|
195 possible to create a matrix. The following statements |
3294 | 196 |
197 @example | |
198 @group | |
199 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
200 a(ones (1, 2), ones (1, 3)) |
3294 | 201 @end group |
202 @end example | |
203 | |
204 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
205 create a 2x3 matrix with all elements equal to 13. |
3294 | 206 |
9159 | 207 The last example could also be written as |
208 | |
209 @example | |
210 @group | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
211 13(ones (2, 3)) |
9159 | 212 @end group |
213 @end example | |
214 | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
215 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
|
216 @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
|
217 multiplication operation. Moreover, multiplication may not be |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
222 @example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
223 @group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
224 @{"Hello"@}(ones (2, 3)) |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
225 @end group |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
226 @end example |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
227 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 particular, when @samp{r} is a row vector, the expressions |
9159 | 234 |
235 @example | |
236 r(ones (1, n), :) | |
237 @end example | |
238 | |
239 @example | |
240 r(ones (n, 1), :) | |
241 @end example | |
242 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
243 @noindent |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 expression. |
9159 | 249 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
250 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
|
251 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
|
252 bigger ones. |
3294 | 253 |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
258 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
|
259 @math{a} containing the values |
6642 | 260 @tex |
261 $a_i = \sqrt{i}$. | |
262 @end tex | |
263 @ifnottex | |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
264 a(i) = sqrt (i). |
6642 | 265 @end ifnottex |
266 | |
267 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
268 @group |
6642 | 269 for i = 1:10 |
270 a(i) = sqrt (i); | |
271 endfor | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
272 @end group |
6642 | 273 @end example |
274 | |
275 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
276 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
|
277 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
|
278 expression |
3294 | 279 |
280 @example | |
281 a = sqrt (1:10); | |
282 @end example | |
283 | |
284 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
285 which avoids the loop entirely. |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
286 |
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 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
|
291 @code{a}, |
3294 | 292 |
293 @example | |
294 @group | |
295 [nr, nc] = size (a); | |
296 x = zeros (nr, n * nc); | |
297 for i = 1:n | |
3602 | 298 x(:,(i-1)*nc+1:i*nc) = a; |
3294 | 299 endfor |
300 @end group | |
301 @end example | |
302 | |
303 @noindent | |
304 is considerably faster than | |
305 | |
306 @example | |
307 @group | |
308 x = a; | |
309 for i = 1:n-1 | |
310 x = [x, a]; | |
311 endfor | |
312 @end group | |
313 @end example | |
314 | |
315 @noindent | |
14033
dfbf6a49847c
doc: Update documentation on indexing expressions
Rik <octave@nomad.inbox5.com>
parents:
13780
diff
changeset
|
316 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
|
317 result. |
3294 | 318 |
6549 | 319 @DOCSTRING(sub2ind) |
320 | |
321 @DOCSTRING(ind2sub) | |
322 | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
323 @DOCSTRING(isindex) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
324 |
4167 | 325 @node Calling Functions |
3294 | 326 @section Calling Functions |
327 | |
328 A @dfn{function} is a name for a particular calculation. Because it has | |
329 a name, you can ask for it by name at any point in the program. For | |
330 example, the function @code{sqrt} computes the square root of a number. | |
331 | |
332 A fixed set of functions are @dfn{built-in}, which means they are | |
333 available in every Octave program. The @code{sqrt} function is one of | |
334 these. In addition, you can define your own functions. | |
335 @xref{Functions and Scripts}, for information about how to do this. | |
336 | |
337 @cindex arguments in function call | |
338 The way to use a function is with a @dfn{function call} expression, | |
339 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
|
340 @dfn{arguments} in parentheses. The arguments are expressions which give |
3294 | 341 the raw materials for the calculation that the function will do. When |
342 there is more than one argument, they are separated by commas. If there | |
343 are no arguments, you can omit the parentheses, but it is a good idea to | |
344 include them anyway, to clearly indicate that a function call was | |
345 intended. Here are some examples: | |
346 | |
347 @example | |
348 @group | |
349 sqrt (x^2 + y^2) # @r{One argument} | |
350 ones (n, m) # @r{Two arguments} | |
351 rand () # @r{No arguments} | |
352 @end group | |
353 @end example | |
354 | |
355 Each function expects a particular number of arguments. For example, the | |
356 @code{sqrt} function must be called with a single argument, the number | |
357 to take the square root of: | |
358 | |
359 @example | |
360 sqrt (@var{argument}) | |
361 @end example | |
362 | |
363 Some of the built-in functions take a variable number of arguments, | |
364 depending on the particular usage, and their behavior is different | |
365 depending on the number of arguments supplied. | |
366 | |
367 Like every other expression, the function call has a value, which is | |
368 computed by the function based on the arguments you give it. In this | |
369 example, the value of @code{sqrt (@var{argument})} is the square root of | |
370 the argument. A function can also have side effects, such as assigning | |
371 the values of certain variables or doing input or output operations. | |
372 | |
373 Unlike most languages, functions in Octave may return multiple values. | |
374 For example, the following statement | |
375 | |
376 @example | |
377 [u, s, v] = svd (a) | |
378 @end example | |
379 | |
380 @noindent | |
381 computes the singular value decomposition of the matrix @code{a} and | |
382 assigns the three result matrices to @code{u}, @code{s}, and @code{v}. | |
383 | |
384 The left side of a multiple assignment expression is itself a list of | |
385 expressions, and is allowed to be a list of variable names or index | |
386 expressions. See also @ref{Index Expressions}, and @ref{Assignment Ops}. | |
387 | |
388 @menu | |
17152
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
389 * Call by Value:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
390 * Recursion:: |
24510
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
391 * Access via Handle:: |
3294 | 392 @end menu |
393 | |
4167 | 394 @node Call by Value |
3294 | 395 @subsection Call by Value |
396 | |
397 In Octave, unlike Fortran, function arguments are passed by value, which | |
398 means that each argument in a function call is evaluated and assigned to | |
399 a temporary location in memory before being passed to the function. | |
400 There is currently no way to specify that a function parameter should be | |
401 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
|
402 impossible to directly alter the value of a function parameter in the |
3294 | 403 calling function. It can only change the local copy within the function |
404 body. For example, the function | |
405 | |
406 @example | |
407 @group | |
408 function f (x, n) | |
409 while (n-- > 0) | |
410 disp (x); | |
411 endwhile | |
412 endfunction | |
413 @end group | |
414 @end example | |
415 | |
416 @noindent | |
417 displays the value of the first argument @var{n} times. In this | |
418 function, the variable @var{n} is used as a temporary variable without | |
419 having to worry that its value might also change in the calling | |
420 function. Call by value is also useful because it is always possible to | |
421 pass constants for any function parameter without first having to | |
422 determine that the function will not attempt to modify the parameter. | |
423 | |
424 The caller may use a variable as the expression for the argument, but | |
425 the called function does not know this: it only knows what value the | |
426 argument had. For example, given a function called as | |
427 | |
428 @example | |
429 @group | |
430 foo = "bar"; | |
431 fcn (foo) | |
432 @end group | |
433 @end example | |
434 | |
435 @noindent | |
436 you should not think of the argument as being ``the variable | |
437 @code{foo}.'' Instead, think of the argument as the string value, | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
438 @qcode{"bar"}. |
3294 | 439 |
440 Even though Octave uses pass-by-value semantics for function arguments, | |
441 values are not copied unnecessarily. For example, | |
442 | |
443 @example | |
444 @group | |
445 x = rand (1000); | |
446 f (x); | |
447 @end group | |
448 @end example | |
449 | |
450 @noindent | |
451 does not actually force two 1000 by 1000 element matrices to exist | |
452 @emph{unless} the function @code{f} modifies the value of its | |
453 argument. Then Octave must create a copy to avoid changing the | |
454 value outside the scope of the function @code{f}, or attempting (and | |
455 probably failing!) to modify the value of a constant or the value of a | |
456 temporary result. | |
457 | |
4167 | 458 @node Recursion |
3294 | 459 @subsection Recursion |
460 @cindex factorial function | |
461 | |
6939 | 462 With some restrictions@footnote{Some of Octave's functions are |
3294 | 463 implemented in terms of functions that cannot be called recursively. |
464 For example, the ODE solver @code{lsode} is ultimately implemented in a | |
465 Fortran subroutine that cannot be called recursively, so @code{lsode} | |
466 should not be called either directly or indirectly from within the | |
467 user-supplied function that @code{lsode} requires. Doing so will result | |
6642 | 468 in an error.}, recursive function calls are allowed. A |
3294 | 469 @dfn{recursive function} is one which calls itself, either directly or |
470 indirectly. For example, here is an inefficient@footnote{It would be | |
471 much better to use @code{prod (1:n)}, or @code{gamma (n+1)} instead, | |
472 after first checking to ensure that the value @code{n} is actually a | |
473 positive integer.} way to compute the factorial of a given integer: | |
474 | |
475 @example | |
476 @group | |
477 function retval = fact (n) | |
478 if (n > 0) | |
479 retval = n * fact (n-1); | |
480 else | |
481 retval = 1; | |
482 endif | |
483 endfunction | |
484 @end group | |
485 @end example | |
486 | |
24510
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
487 @noindent |
3294 | 488 This function is recursive because it calls itself directly. It |
489 eventually terminates because each time it calls itself, it uses an | |
490 argument that is one less than was used for the previous call. Once the | |
491 argument is no longer greater than zero, it does not call itself, and | |
492 the recursion ends. | |
493 | |
494 The built-in variable @code{max_recursion_depth} specifies a limit to | |
495 the recursion depth and prevents Octave from recursing infinitely. | |
496 | |
3371 | 497 @DOCSTRING(max_recursion_depth) |
3294 | 498 |
24510
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
499 @node Access via Handle |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
500 @subsection Access via Handle |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
501 @cindex function handle |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
502 @cindex indirect function call |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
503 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
504 @opindex @@ function handle |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
505 A function may be abstracted and referenced via a function handle acquired |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
506 using the special operator @samp{@@}. For example, |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
507 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
508 @example |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
509 @group |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
510 f = @@plus; |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
511 f (2, 2) |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
512 @result{} 4 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
513 @end group |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
514 @end example |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
515 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
516 @noindent |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
517 is equivalent to calling @code{plus (2, 2)} directly. Beyond abstraction for |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
518 general programming, function handles find use in callback methods for figures |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
519 and graphics by adding listeners to properties or assigning pre-existing |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
520 actions, such as in the following example: |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
521 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
522 @cindex figure deletefcn |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
523 @example |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
524 @group |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
525 function mydeletefcn (h, ~, msg) |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
526 printf (msg); |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
527 endfunction |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
528 sombrero; |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
529 set (gcf, "deletefcn", @{@@mydeletefcn, "Bye!\n"@}); |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
530 close; |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
531 @end group |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
532 @end example |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
533 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
534 @noindent |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
535 The above will print "Bye!" to the terminal upon the closing (deleting) of the |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
536 figure. There are many graphics property actions for which a callback function |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
537 may be assigned, including, @code{buttondownfcn}, @code{windowscrollwheelfcn}, |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
538 @code{createfcn}, @code{deletefcn}, @code{keypressfcn}, etc. |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
539 |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
540 Note that the @samp{@@} character also plays a role in defining class |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
541 functions, i.e., methods, but not as a syntactical element. Rather it begins a |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
542 directory name containing methods for a class that shares the directory name |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
543 sans the @samp{@@} character. See @ref{Object Oriented Programming}. |
a2569d574ae5
Add a help entry and documentation for @ character (bug #52771).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24507
diff
changeset
|
544 |
4167 | 545 @node Arithmetic Ops |
3294 | 546 @section Arithmetic Operators |
547 @cindex arithmetic operators | |
548 @cindex operators, arithmetic | |
549 @cindex addition | |
550 @cindex subtraction | |
551 @cindex multiplication | |
552 @cindex matrix multiplication | |
553 @cindex division | |
554 @cindex quotient | |
555 @cindex negation | |
556 @cindex unary minus | |
557 @cindex exponentiation | |
558 @cindex transpose | |
559 @cindex Hermitian operator | |
560 @cindex transpose, complex-conjugate | |
561 @cindex complex-conjugate transpose | |
562 | |
563 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
|
564 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
|
565 (@pxref{Broadcasting}). |
3294 | 566 |
13780
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
12627
diff
changeset
|
567 @table @asis |
3294 | 568 @item @var{x} + @var{y} |
569 @opindex + | |
570 Addition. If both operands are matrices, the number of rows and columns | |
14149
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
571 must both agree, or they must be broadcastable to the same shape. |
3294 | 572 |
573 @item @var{x} .+ @var{y} | |
574 @opindex .+ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
575 Element-by-element addition. This operator is equivalent to @code{+}. |
3294 | 576 |
577 @item @var{x} - @var{y} | |
578 @opindex - | |
579 Subtraction. If both operands are matrices, the number of rows and | |
14149
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
580 columns of both must agree, or they must be broadcastable to the same |
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
581 shape. |
3294 | 582 |
583 @item @var{x} .- @var{y} | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
584 Element-by-element subtraction. This operator is equivalent to @code{-}. |
3294 | 585 |
586 @item @var{x} * @var{y} | |
587 @opindex * | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
588 Matrix multiplication. The number of columns of @var{x} must agree with |
24454
b9d482dd90f3
doc: Fix mistaken use of space between function and '(' in documentation (bug #52723).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
589 the number of rows of @var{y}. |
3294 | 590 |
591 @item @var{x} .* @var{y} | |
592 @opindex .* | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
593 Element-by-element multiplication. If both operands are matrices, the |
14149
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
594 number of rows and columns must both agree, or they must be |
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
595 broadcastable to the same shape. |
3294 | 596 |
597 @item @var{x} / @var{y} | |
598 @opindex / | |
599 Right division. This is conceptually equivalent to the expression | |
600 | |
601 @example | |
602 (inverse (y') * x')' | |
603 @end example | |
604 | |
605 @noindent | |
606 but it is computed without forming the inverse of @var{y'}. | |
607 | |
608 If the system is not square, or if the coefficient matrix is singular, | |
609 a minimum norm solution is computed. | |
610 | |
611 @item @var{x} ./ @var{y} | |
612 @opindex ./ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
613 Element-by-element right division. |
3294 | 614 |
615 @item @var{x} \ @var{y} | |
616 @opindex \ | |
617 Left division. This is conceptually equivalent to the expression | |
618 | |
619 @example | |
620 inverse (x) * y | |
621 @end example | |
622 | |
623 @noindent | |
624 but it is computed without forming the inverse of @var{x}. | |
625 | |
626 If the system is not square, or if the coefficient matrix is singular, | |
627 a minimum norm solution is computed. | |
628 | |
629 @item @var{x} .\ @var{y} | |
630 @opindex .\ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
631 Element-by-element left division. Each element of @var{y} is divided |
3294 | 632 by each corresponding element of @var{x}. |
633 | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
634 @item @var{x} ^ @var{y} |
3294 | 635 @itemx @var{x} ** @var{y} |
636 @opindex ** | |
637 @opindex ^ | |
638 Power operator. If @var{x} and @var{y} are both scalars, this operator | |
639 returns @var{x} raised to the power @var{y}. If @var{x} is a scalar and | |
640 @var{y} is a square matrix, the result is computed using an eigenvalue | |
7001 | 641 expansion. If @var{x} is a square matrix, the result is computed by |
3294 | 642 repeated multiplication if @var{y} is an integer, and by an eigenvalue |
643 expansion if @var{y} is not an integer. An error results if both | |
644 @var{x} and @var{y} are matrices. | |
645 | |
646 The implementation of this operator needs to be improved. | |
647 | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
648 @item @var{x} .^ @var{y} |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
649 @itemx @var{x} .** @var{y} |
3294 | 650 @opindex .** |
651 @opindex .^ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
652 Element-by-element power operator. If both operands are matrices, the |
14149
f1ff06a1d73a
doc: Mention broadcasting in more relevant places.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
653 number of rows and columns must both agree, or they must be |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
654 broadcastable to the same shape. If several complex results are |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
655 possible, the one with smallest non-negative argument (angle) is taken. |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
656 This rule may return a complex root even when a real root is also possible. |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
657 Use @code{realpow}, @code{realsqrt}, @code{cbrt}, or @code{nthroot} if a |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14149
diff
changeset
|
658 real result is preferred. |
3294 | 659 |
660 @item -@var{x} | |
661 @opindex - | |
662 Negation. | |
663 | |
664 @item +@var{x} | |
665 @opindex + | |
666 Unary plus. This operator has no effect on the operand. | |
667 | |
668 @item @var{x}' | |
669 @opindex ' | |
670 Complex conjugate transpose. For real arguments, this operator is the | |
671 same as the transpose operator. For complex arguments, this operator is | |
672 equivalent to the expression | |
673 | |
674 @example | |
675 conj (x.') | |
676 @end example | |
677 | |
678 @item @var{x}.' | |
679 @opindex .' | |
680 Transpose. | |
681 @end table | |
682 | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
683 Note that because Octave's element-by-element operators begin with a |
3294 | 684 @samp{.}, there is a possible ambiguity for statements like |
685 | |
686 @example | |
687 1./m | |
688 @end example | |
689 | |
690 @noindent | |
691 because the period could be interpreted either as part of the constant | |
692 or as part of the operator. To resolve this conflict, Octave treats the | |
693 expression as if you had typed | |
694 | |
695 @example | |
696 (1) ./ m | |
697 @end example | |
698 | |
699 @noindent | |
700 and not | |
701 | |
702 @example | |
703 (1.) / m | |
704 @end example | |
705 | |
706 @noindent | |
707 Although this is inconsistent with the normal behavior of Octave's | |
708 lexer, which usually prefers to break the input into tokens by | |
709 preferring the longest possible match at any given point, it is more | |
710 useful in this case. | |
711 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
712 @opindex ' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
713 @DOCSTRING(ctranspose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
714 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
715 @opindex .\ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
716 @DOCSTRING(ldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
717 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
718 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
719 @DOCSTRING(minus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
720 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
721 @opindex \ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
722 @DOCSTRING(mldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
723 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
724 @opindex ** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
725 @opindex ^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
726 @DOCSTRING(mpower) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
727 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
728 @opindex / |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
729 @DOCSTRING(mrdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
730 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
731 @opindex * |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
732 @DOCSTRING(mtimes) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
733 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
734 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
735 @DOCSTRING(plus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
736 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
737 @opindex .** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
738 @opindex .^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
739 @DOCSTRING(power) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
740 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
741 @opindex ./ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
742 @DOCSTRING(rdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
743 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
744 @opindex .* |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
745 @DOCSTRING(times) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
746 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
747 @opindex .' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
748 @DOCSTRING(transpose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
749 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
750 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
751 @DOCSTRING(uminus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
752 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
753 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
754 @DOCSTRING(uplus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
755 |
4167 | 756 @node Comparison Ops |
3294 | 757 @section Comparison Operators |
758 @cindex comparison expressions | |
759 @cindex expressions, comparison | |
760 @cindex relational operators | |
761 @cindex operators, relational | |
762 @cindex less than operator | |
763 @cindex greater than operator | |
764 @cindex equality operator | |
765 @cindex tests for equality | |
766 @cindex equality, tests for | |
767 | |
768 @dfn{Comparison operators} compare numeric values for relationships | |
769 such as equality. They are written using | |
770 @emph{relational operators}. | |
771 | |
772 All of Octave's comparison operators return a value of 1 if the | |
773 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
|
774 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
|
775 @xref{Broadcasting}. For example: |
3294 | 776 |
777 @example | |
778 @group | |
779 [1, 2; 3, 4] == [1, 3; 2, 4] | |
780 @result{} 1 0 | |
781 0 1 | |
782 @end group | |
783 @end example | |
784 | |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14038
diff
changeset
|
785 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
|
786 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
|
787 in turn, and the result is the same size as the matrix. |
3294 | 788 |
789 @table @code | |
790 @item @var{x} < @var{y} | |
791 @opindex < | |
792 True if @var{x} is less than @var{y}. | |
793 | |
794 @item @var{x} <= @var{y} | |
795 @opindex <= | |
796 True if @var{x} is less than or equal to @var{y}. | |
797 | |
798 @item @var{x} == @var{y} | |
799 @opindex == | |
800 True if @var{x} is equal to @var{y}. | |
801 | |
802 @item @var{x} >= @var{y} | |
803 @opindex >= | |
804 True if @var{x} is greater than or equal to @var{y}. | |
805 | |
806 @item @var{x} > @var{y} | |
807 @opindex > | |
808 True if @var{x} is greater than @var{y}. | |
809 | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
810 @item @var{x} != @var{y} |
3294 | 811 @itemx @var{x} ~= @var{y} |
812 @opindex != | |
813 @opindex ~= | |
814 True if @var{x} is not equal to @var{y}. | |
815 @end table | |
816 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
817 For complex numbers, the following ordering is defined: |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
818 @var{z1} < @var{z2} |
16826
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
14856
diff
changeset
|
819 if and only if |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
820 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
821 @example |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9578
diff
changeset
|
822 @group |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
823 abs (@var{z1}) < abs (@var{z2}) |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
824 || (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
|
825 @end group |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
826 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
827 |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
828 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
|
829 @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
|
830 parts. |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
831 |
3294 | 832 String comparisons may also be performed with the @code{strcmp} |
833 function, not with the comparison operators listed above. | |
834 @xref{Strings}. | |
835 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
836 @opindex == |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
837 @DOCSTRING(eq) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
838 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
839 @opindex >= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
840 @DOCSTRING(ge) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
841 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
842 @opindex > |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
843 @DOCSTRING(gt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
844 |
6550 | 845 @DOCSTRING(isequal) |
846 | |
16935
a7b2fc7fe1a9
binocdf.m: Reverse calling convention to betaincinv to preserve accuracy when p =~ 1.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
847 @DOCSTRING(isequaln) |
6550 | 848 |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
849 @opindex <= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
850 @DOCSTRING(le) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
851 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
852 @opindex < |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
853 @DOCSTRING(lt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
854 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
855 @opindex != |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
856 @opindex ~= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
857 @DOCSTRING(ne) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
858 |
4167 | 859 @node Boolean Expressions |
3294 | 860 @section Boolean Expressions |
861 @cindex expressions, boolean | |
862 @cindex boolean expressions | |
863 @cindex expressions, logical | |
864 @cindex logical expressions | |
865 @cindex operators, boolean | |
866 @cindex boolean operators | |
867 @cindex logical operators | |
868 @cindex operators, logical | |
869 @cindex and operator | |
870 @cindex or operator | |
871 @cindex not operator | |
872 | |
873 @menu | |
17152
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
874 * Element-by-element Boolean Operators:: |
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
16935
diff
changeset
|
875 * Short-circuit Boolean Operators:: |
3294 | 876 @end menu |
877 | |
4167 | 878 @node Element-by-element Boolean Operators |
3294 | 879 @subsection Element-by-element Boolean Operators |
880 @cindex element-by-element evaluation | |
881 | |
882 An @dfn{element-by-element boolean expression} is a combination of | |
883 comparison expressions using the boolean | |
884 operators ``or'' (@samp{|}), ``and'' (@samp{&}), and ``not'' (@samp{!}), | |
885 along with parentheses to control nesting. The truth of the boolean | |
886 expression is computed by combining the truth values of the | |
887 corresponding elements of the component expressions. A value is | |
888 considered to be false if it is zero, and true otherwise. | |
889 | |
890 Element-by-element boolean expressions can be used wherever comparison | |
891 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
|
892 statements. However, a matrix value used as the condition in an |
3294 | 893 @code{if} or @code{while} statement is only true if @emph{all} of its |
894 elements are nonzero. | |
895 | |
896 Like comparison operations, each element of an element-by-element | |
897 boolean expression also has a numeric value (1 if true, 0 if false) that | |
898 comes into play if the result of the boolean expression is stored in a | |
899 variable, or used in arithmetic. | |
900 | |
901 Here are descriptions of the three element-by-element boolean operators. | |
902 | |
903 @table @code | |
904 @item @var{boolean1} & @var{boolean2} | |
905 @opindex & | |
906 Elements of the result are true if both corresponding elements of | |
907 @var{boolean1} and @var{boolean2} are true. | |
908 | |
909 @item @var{boolean1} | @var{boolean2} | |
910 @opindex | | |
911 Elements of the result are true if either of the corresponding elements | |
912 of @var{boolean1} or @var{boolean2} is true. | |
913 | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
914 @item ! @var{boolean} |
3294 | 915 @itemx ~ @var{boolean} |
916 @opindex ~ | |
917 @opindex ! | |
918 Each element of the result is true if the corresponding element of | |
919 @var{boolean} is false. | |
920 @end table | |
921 | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
922 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
|
923 expression |
3294 | 924 |
925 @example | |
926 [1, 0; 0, 1] & [1, 0; 2, 3] | |
927 @end example | |
928 | |
929 @noindent | |
930 returns a two by two identity matrix. | |
931 | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
14116
diff
changeset
|
932 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
|
933 In particular, if one of the operands is a scalar and the other a |
3294 | 934 matrix, the operator is applied to the scalar and each element of the |
935 matrix. | |
936 | |
937 For the binary element-by-element boolean operators, both subexpressions | |
938 @var{boolean1} and @var{boolean2} are evaluated before computing the | |
939 result. This can make a difference when the expressions have side | |
940 effects. For example, in the expression | |
941 | |
942 @example | |
943 a & b++ | |
944 @end example | |
945 | |
946 @noindent | |
947 the value of the variable @var{b} is incremented even if the variable | |
948 @var{a} is zero. | |
949 | |
950 This behavior is necessary for the boolean operators to work as | |
951 described for matrix-valued operands. | |
952 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
953 @opindex & |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
954 @DOCSTRING(and) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
955 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
956 @opindex ~ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
957 @opindex ! |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
958 @DOCSTRING(not) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
959 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
960 @opindex | |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
961 @DOCSTRING(or) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
962 |
4167 | 963 @node Short-circuit Boolean Operators |
3294 | 964 @subsection Short-circuit Boolean Operators |
965 @cindex short-circuit evaluation | |
966 | |
967 Combined with the implicit conversion to scalar values in @code{if} and | |
968 @code{while} conditions, Octave's element-by-element boolean operators | |
969 are often sufficient for performing most logical operations. However, | |
970 it is sometimes desirable to stop evaluating a boolean expression as | |
971 soon as the overall truth value can be determined. Octave's | |
972 @dfn{short-circuit} boolean operators work this way. | |
973 | |
974 @table @code | |
975 @item @var{boolean1} && @var{boolean2} | |
976 @opindex && | |
977 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 978 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 979 If it is false, the result of the overall expression is 0. If it is |
980 true, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 981 scalar using the equivalent of the operation @code{all |
20659
4a82f565a669
doc: Fix typo in short-circuit operators documentation (bug #46280).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
982 (@var{boolean2}(:))}. If it is true, the result of the overall expression |
3294 | 983 is 1. Otherwise, the result of the overall expression is 0. |
984 | |
6632 | 985 @strong{Warning:} there is one exception to the rule of evaluating |
986 @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
|
987 empty matrix. The truth value of an empty matrix is always @code{false} |
6632 | 988 so @code{[] && true} evaluates to @code{false} even though |
989 @code{all ([])} is @code{true}. | |
990 | |
3294 | 991 @item @var{boolean1} || @var{boolean2} |
992 @opindex || | |
993 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 994 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 995 If it is true, the result of the overall expression is 1. If it is |
996 false, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 997 scalar using the equivalent of the operation @code{all |
20659
4a82f565a669
doc: Fix typo in short-circuit operators documentation (bug #46280).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
998 (@var{boolean2}(:))}. If it is true, the result of the overall expression |
3294 | 999 is 1. Otherwise, the result of the overall expression is 0. |
6632 | 1000 |
1001 @strong{Warning:} the truth value of an empty matrix is always @code{false}, | |
1002 see the previous list item for details. | |
3294 | 1003 @end table |
1004 | |
1005 The fact that both operands may not be evaluated before determining the | |
1006 overall truth value of the expression can be important. For example, in | |
1007 the expression | |
1008 | |
1009 @example | |
1010 a && b++ | |
1011 @end example | |
1012 | |
1013 @noindent | |
1014 the value of the variable @var{b} is only incremented if the variable | |
1015 @var{a} is nonzero. | |
1016 | |
1017 This can be used to write somewhat more concise code. For example, it | |
1018 is possible write | |
1019 | |
1020 @example | |
1021 @group | |
1022 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
1023 if (nargin > 2 && ischar (c)) |
3294 | 1024 @dots{} |
1025 @end group | |
1026 @end example | |
1027 | |
1028 @noindent | |
1029 instead of having to use two @code{if} statements to avoid attempting to | |
1030 evaluate an argument that doesn't exist. For example, without the | |
1031 short-circuit feature, it would be necessary to write | |
1032 | |
1033 @example | |
1034 @group | |
1035 function f (a, b, c) | |
1036 if (nargin > 2) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
1037 if (ischar (c)) |
3294 | 1038 @dots{} |
1039 @end group | |
1040 @end example | |
1041 | |
6632 | 1042 @noindent |
3294 | 1043 Writing |
1044 | |
1045 @example | |
1046 @group | |
1047 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
1048 if (nargin > 2 & ischar (c)) |
3294 | 1049 @dots{} |
1050 @end group | |
1051 @end example | |
1052 | |
1053 @noindent | |
1054 would result in an error if @code{f} were called with one or two | |
1055 arguments because Octave would be forced to try to evaluate both of the | |
1056 operands for the operator @samp{&}. | |
1057 | |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1058 @sc{matlab} has special behavior that allows the operators @samp{&} and |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
1059 @samp{|} to short-circuit when used in the truth expression for @code{if} and |
22620
74fb14727a30
doc: Remove DOCSTRING references to non-existent functions (bug #49329).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1060 @code{while} statements. Octave behaves the same way for compatibility, |
74fb14727a30
doc: Remove DOCSTRING references to non-existent functions (bug #49329).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1061 however, the use of the @samp{&} and @samp{|} operators in this way is |
74fb14727a30
doc: Remove DOCSTRING references to non-existent functions (bug #49329).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1062 strongly discouraged and a warning will be issued. Instead, you should use |
74fb14727a30
doc: Remove DOCSTRING references to non-existent functions (bug #49329).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1063 the @samp{&&} and @samp{||} operators that always have short-circuit behavior. |
20745
c4f79fc9281a
doc: Resolve two undocumented functions in manual.
Rik <rik@octave.org>
parents:
20659
diff
changeset
|
1064 |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
1065 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
|
1066 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
|
1067 function. |
10308 | 1068 |
11552
6b6e9051ecb8
Add merge/ifelse function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
1069 @DOCSTRING(merge) |
10308 | 1070 |
4167 | 1071 @node Assignment Ops |
3294 | 1072 @section Assignment Expressions |
1073 @cindex assignment expressions | |
1074 @cindex assignment operators | |
1075 @cindex operators, assignment | |
1076 @cindex expressions, assignment | |
1077 | |
1078 @opindex = | |
1079 | |
1080 An @dfn{assignment} is an expression that stores a new value into a | |
1081 variable. For example, the following expression assigns the value 1 to | |
1082 the variable @code{z}: | |
1083 | |
1084 @example | |
1085 z = 1 | |
1086 @end example | |
1087 | |
6632 | 1088 @noindent |
3294 | 1089 After this expression is executed, the variable @code{z} has the value 1. |
1090 Whatever old value @code{z} had before the assignment is forgotten. | |
1091 The @samp{=} sign is called an @dfn{assignment operator}. | |
1092 | |
1093 Assignments can store string values also. For example, the following | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
1094 expression would store the value @qcode{"this food is good"} in the |
3294 | 1095 variable @code{message}: |
1096 | |
1097 @example | |
1098 @group | |
1099 thing = "food" | |
1100 predicate = "good" | |
1101 message = [ "this " , thing , " is " , predicate ] | |
1102 @end group | |
1103 @end example | |
1104 | |
1105 @noindent | |
1106 (This also illustrates concatenation of strings.) | |
1107 | |
1108 @cindex side effect | |
1109 Most operators (addition, concatenation, and so on) have no effect | |
1110 except to compute a value. If you ignore the value, you might as well | |
1111 not use the operator. An assignment operator is different. It does | |
1112 produce a value, but even if you ignore the value, the assignment still | |
1113 makes itself felt through the alteration of the variable. We call this | |
1114 a @dfn{side effect}. | |
1115 | |
1116 @cindex lvalue | |
1117 The left-hand operand of an assignment need not be a variable | |
1118 (@pxref{Variables}). It can also be an element of a matrix | |
1119 (@pxref{Index Expressions}) or a list of return values | |
1120 (@pxref{Calling Functions}). These are all called @dfn{lvalues}, which | |
1121 means they can appear on the left-hand side of an assignment operator. | |
1122 The right-hand operand may be any expression. It produces the new value | |
1123 which the assignment stores in the specified variable, matrix element, | |
1124 or list of return values. | |
1125 | |
1126 It is important to note that variables do @emph{not} have permanent types. | |
1127 The type of a variable is simply the type of whatever value it happens | |
1128 to hold at the moment. In the following program fragment, the variable | |
1129 @code{foo} has a numeric value at first, and a string value later on: | |
1130 | |
1131 @example | |
1132 @group | |
1133 octave:13> foo = 1 | |
1134 foo = 1 | |
1135 octave:13> foo = "bar" | |
1136 foo = bar | |
1137 @end group | |
1138 @end example | |
1139 | |
1140 @noindent | |
1141 When the second assignment gives @code{foo} a string value, the fact that | |
1142 it previously had a numeric value is forgotten. | |
1143 | |
1144 Assignment of a scalar to an indexed matrix sets all of the elements | |
1145 that are referenced by the indices to the scalar value. For example, if | |
1146 @code{a} is a matrix with at least two columns, | |
1147 | |
1148 @example | |
1149 @group | |
1150 a(:, 2) = 5 | |
1151 @end group | |
1152 @end example | |
1153 | |
1154 @noindent | |
1155 sets all the elements in the second column of @code{a} to 5. | |
1156 | |
1157 Assigning an empty matrix @samp{[]} works in most cases to allow you to | |
1158 delete rows or columns of matrices and vectors. @xref{Empty Matrices}. | |
1159 For example, given a 4 by 5 matrix @var{A}, the assignment | |
1160 | |
1161 @example | |
1162 A (3, :) = [] | |
1163 @end example | |
1164 | |
1165 @noindent | |
1166 deletes the third row of @var{A}, and the assignment | |
1167 | |
1168 @example | |
1169 A (:, 1:2:5) = [] | |
1170 @end example | |
1171 | |
1172 @noindent | |
6672 | 1173 deletes the first, third, and fifth columns. |
3294 | 1174 |
1175 An assignment is an expression, so it has a value. Thus, @code{z = 1} | |
1176 as an expression has the value 1. One consequence of this is that you | |
1177 can write multiple assignments together: | |
1178 | |
1179 @example | |
1180 x = y = z = 0 | |
1181 @end example | |
1182 | |
1183 @noindent | |
1184 stores the value 0 in all three variables. It does this because the | |
1185 value of @code{z = 0}, which is 0, is stored into @code{y}, and then | |
1186 the value of @code{y = z = 0}, which is 0, is stored into @code{x}. | |
1187 | |
1188 This is also true of assignments to lists of values, so the following is | |
1189 a valid expression | |
1190 | |
1191 @example | |
1192 [a, b, c] = [u, s, v] = svd (a) | |
1193 @end example | |
1194 | |
1195 @noindent | |
1196 that is exactly equivalent to | |
1197 | |
1198 @example | |
1199 @group | |
1200 [u, s, v] = svd (a) | |
1201 a = u | |
1202 b = s | |
1203 c = v | |
1204 @end group | |
1205 @end example | |
1206 | |
1207 In expressions like this, the number of values in each part of the | |
1208 expression need not match. For example, the expression | |
1209 | |
1210 @example | |
1211 [a, b] = [u, s, v] = svd (a) | |
1212 @end example | |
1213 | |
1214 @noindent | |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18842
diff
changeset
|
1215 is equivalent to |
3294 | 1216 |
1217 @example | |
1218 @group | |
1219 [u, s, v] = svd (a) | |
1220 a = u | |
1221 b = s | |
1222 @end group | |
1223 @end example | |
1224 | |
6632 | 1225 @noindent |
1226 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
|
1227 not exceed the number of values on the right side. For example, the |
6632 | 1228 following will produce an error. |
1229 | |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1230 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
1231 @group |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7768
diff
changeset
|
1232 [a, b, c, d] = [u, s, v] = svd (a); |
7031 | 1233 @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
|
1234 @end group |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1235 @end example |
6632 | 1236 |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1237 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
|
1238 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
|
1239 anywhere: |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1240 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1241 @example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1242 @group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1243 [~, s, v] = svd (a); |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1244 @end group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1245 @end example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1246 |
10228 | 1247 This is cleaner and more memory efficient than using a dummy variable. |
1248 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
|
1249 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
|
1250 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
|
1251 |
6642 | 1252 @opindex += |
1253 A very common programming pattern is to increment an existing variable | |
1254 with a given value, like this | |
1255 | |
1256 @example | |
1257 a = a + 2; | |
1258 @end example | |
1259 | |
1260 @noindent | |
1261 This can be written in a clearer and more condensed form using the | |
1262 @code{+=} operator | |
1263 | |
1264 @example | |
1265 a += 2; | |
1266 @end example | |
1267 | |
1268 @noindent | |
1269 @opindex -= | |
1270 @opindex *= | |
1271 @opindex /= | |
1272 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
|
1273 multiplication (@code{*=}), and division (@code{/=}). An expression |
6642 | 1274 of the form |
1275 | |
1276 @example | |
1277 @var{expr1} @var{op}= @var{expr2} | |
1278 @end example | |
1279 | |
1280 @noindent | |
1281 is evaluated as | |
1282 | |
1283 @example | |
1284 @var{expr1} = (@var{expr1}) @var{op} (@var{expr2}) | |
1285 @end example | |
1286 | |
1287 @noindent | |
18842
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1288 where @var{op} can be either @code{+}, @code{-}, @code{*}, or @code{/}, |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1289 as long as @var{expr2} is a simple expression with no side effects. If |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1290 @var{expr2} also contains an assignment operator, then this expression |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1291 is evaluated as |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1292 |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1293 @example |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19131
diff
changeset
|
1294 @group |
18842
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1295 @var{temp} = @var{expr2} |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1296 @var{expr1} = (@var{expr1}) @var{op} @var{temp} |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19131
diff
changeset
|
1297 @end group |
18842
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1298 @end example |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1299 |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1300 @noindent |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1301 where @var{temp} is a placeholder temporary value storing the computed |
e6a4fa91a2f1
doc: Clarify order of evaluation of compound assignment expressions
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
1302 result of evaluating @var{expr2}. So, the expression |
6642 | 1303 |
1304 @example | |
1305 a *= b+1 | |
1306 @end example | |
1307 | |
1308 @noindent | |
1309 is evaluated as | |
1310 | |
1311 @example | |
1312 a = a * (b+1) | |
1313 @end example | |
1314 | |
1315 @noindent | |
1316 and @emph{not} | |
1317 | |
1318 @example | |
1319 a = a * b + 1 | |
1320 @end example | |
1321 | |
3294 | 1322 You can use an assignment anywhere an expression is called for. For |
1323 example, it is valid to write @code{x != (y = 1)} to set @code{y} to 1 | |
1324 and then test whether @code{x} equals 1. But this style tends to make | |
1325 programs hard to read. Except in a one-shot program, you should rewrite | |
1326 it to get rid of such nesting of assignments. This is never very hard. | |
1327 | |
1328 @cindex increment operator | |
1329 @cindex decrement operator | |
1330 @cindex operators, increment | |
1331 @cindex operators, decrement | |
1332 | |
4167 | 1333 @node Increment Ops |
3294 | 1334 @section Increment Operators |
1335 | |
1336 @emph{Increment operators} increase or decrease the value of a variable | |
1337 by 1. The operator to increment a variable is written as @samp{++}. It | |
1338 may be used to increment a variable either before or after taking its | |
1339 value. | |
1340 | |
1341 For example, to pre-increment the variable @var{x}, you would write | |
1342 @code{++@var{x}}. This would add one to @var{x} and then return the new | |
1343 value of @var{x} as the result of the expression. It is exactly the | |
1344 same as the expression @code{@var{x} = @var{x} + 1}. | |
1345 | |
1346 To post-increment a variable @var{x}, you would write @code{@var{x}++}. | |
1347 This adds one to the variable @var{x}, but returns the value that | |
1348 @var{x} had prior to incrementing it. For example, if @var{x} is equal | |
1349 to 2, the result of the expression @code{@var{x}++} is 2, and the new | |
1350 value of @var{x} is 3. | |
1351 | |
1352 For matrix and vector arguments, the increment and decrement operators | |
1353 work on each element of the operand. | |
1354 | |
1355 Here is a list of all the increment and decrement expressions. | |
1356 | |
1357 @table @code | |
1358 @item ++@var{x} | |
1359 @opindex ++ | |
1360 This expression increments the variable @var{x}. The value of the | |
1361 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1362 expression @code{@var{x} = @var{x} + 1}. | |
1363 | |
1364 @item --@var{x} | |
1365 @opindex @code{--} | |
1366 This expression decrements the variable @var{x}. The value of the | |
1367 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1368 expression @code{@var{x} = @var{x} - 1}. | |
1369 | |
1370 @item @var{x}++ | |
1371 @opindex ++ | |
1372 This expression causes the variable @var{x} to be incremented. The | |
1373 value of the expression is the @emph{old} value of @var{x}. | |
1374 | |
1375 @item @var{x}-- | |
1376 @opindex @code{--} | |
1377 This expression causes the variable @var{x} to be decremented. The | |
1378 value of the expression is the @emph{old} value of @var{x}. | |
1379 @end table | |
1380 | |
4167 | 1381 @node Operator Precedence |
3294 | 1382 @section Operator Precedence |
1383 @cindex operator precedence | |
1384 | |
1385 @dfn{Operator precedence} determines how operators are grouped, when | |
1386 different operators appear close by in one expression. For example, | |
1387 @samp{*} has higher precedence than @samp{+}. Thus, the expression | |
1388 @code{a + b * c} means to multiply @code{b} and @code{c}, and then add | |
1389 @code{a} to the product (i.e., @code{a + (b * c)}). | |
1390 | |
1391 You can overrule the precedence of the operators by using parentheses. | |
1392 You can think of the precedence rules as saying where the parentheses | |
1393 are assumed if you do not write parentheses yourself. In fact, it is | |
1394 wise to use parentheses whenever you have an unusual combination of | |
1395 operators, because other people who read the program may not remember | |
1396 what the precedence is in this case. You might forget as well, and then | |
1397 you too could make a mistake. Explicit parentheses will help prevent | |
1398 any such mistake. | |
1399 | |
1400 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
|
1401 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
|
1402 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
|
1403 @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
|
1404 @code{a = (b = c)}. |
3294 | 1405 |
1406 The precedence of prefix unary operators is important when another | |
1407 operator follows the operand. For example, @code{-x^2} means | |
1408 @code{-(x^2)}, because @samp{-} has lower precedence than @samp{^}. | |
1409 | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1410 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
|
1411 precedence. Unless noted, all operators group left to right. |
3294 | 1412 |
1413 @table @code | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1414 @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
|
1415 @samp{()} @samp{@{@}} @samp{.} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1416 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1417 @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
|
1418 @samp{++} @samp{--} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1419 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1420 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
|
1421 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1422 @item transpose and exponentiation |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1423 @samp{'} @samp{.'} @samp{^} @samp{**} @samp{.^} @samp{.**} |
3294 | 1424 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1425 @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
|
1426 @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
|
1427 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1428 @item multiply and divide |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1429 @samp{*} @samp{/} @samp{\} @samp{.\} @samp{.*} @samp{./} |
3294 | 1430 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1431 @item add, subtract |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1432 @samp{+} @samp{-} |
3294 | 1433 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1434 @item colon |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1435 @samp{:} |
3294 | 1436 |
1437 @item relational | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1438 @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
|
1439 @samp{~=} |
3294 | 1440 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1441 @item element-wise "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1442 @samp{&} |
3294 | 1443 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1444 @item element-wise "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1445 @samp{|} |
3294 | 1446 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1447 @item logical "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1448 @samp{&&} |
3294 | 1449 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1450 @item logical "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1451 @samp{||} |
3294 | 1452 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1453 @item assignment |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1454 @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
|
1455 @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
|
1456 @samp{&=} |
3294 | 1457 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1458 These operators group right to left. |
3294 | 1459 @end table |