Mercurial > hg > octave-lyh
comparison doc/interpreter/expr.txi @ 14038:b0cdd60db5e5 stable
doc: Grammarcheck documentation ahead of 3.6.0 release.
* basics.txi, container.txi, contrib.txi, debug.txi, expr.txi, func.txi,
install.txi, io.txi, package.txi, polyarea.m, ezcontour.m, ezcontourf.m,
ezmesh.m, ezmeshc.m, ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m,
assert.m, amd.cc, chol.cc, colamd.cc, rand.cc: Grammarcheck documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 12 Dec 2011 21:01:27 -0800 |
parents | dfbf6a49847c |
children | 951eacaf9381 |
comparison
equal
deleted
inserted
replaced
14037:4228c102eca9 | 14038:b0cdd60db5e5 |
---|---|
60 or @math{N} indices where @math{N} is the dimension of the array. | 60 or @math{N} indices where @math{N} is the dimension of the array. |
61 When using a single index expression to index 2-D or higher data the | 61 When using a single index expression to index 2-D or higher data the |
62 elements of the array are taken in column-first order (like Fortran). | 62 elements of the array are taken in column-first order (like Fortran). |
63 | 63 |
64 The output from indexing assumes the dimensions of the index | 64 The output from indexing assumes the dimensions of the index |
65 expression. For example, | 65 expression. For example: |
66 | 66 |
67 @example | 67 @example |
68 @group | 68 @group |
69 a(2) # result is a scalar | 69 a(2) # result is a scalar |
70 a(1:2) # result is a row vector | 70 a(1:2) # result is a row vector |
75 As a special case, when a colon is used as a single index, the output | 75 As a special case, when a colon is used as a single index, the output |
76 is a column vector containing all the elements of the vector or | 76 is a column vector containing all the elements of the vector or |
77 matrix. For example: | 77 matrix. For example: |
78 | 78 |
79 @example | 79 @example |
80 @group | |
80 a(:) # result is a column vector | 81 a(:) # result is a column vector |
81 a(:)' # result is a row vector | 82 a(:)' # result is a row vector |
83 @end group | |
82 @end example | 84 @end example |
83 | 85 |
84 The above two code idioms are often used in place of @code{reshape} | 86 The above two code idioms are often used in place of @code{reshape} |
85 when a simple vector, rather than an arbitrarily sized array, is | 87 when a simple vector, rather than an arbitrarily sized array, is |
86 needed. | 88 needed. |
147 are folded into a single dimension with an extent equal to the product | 149 are folded into a single dimension with an extent equal to the product |
148 of extents of the original dimensions. This is easiest to understand | 150 of extents of the original dimensions. This is easiest to understand |
149 with an example. | 151 with an example. |
150 | 152 |
151 @example | 153 @example |
152 @group | |
153 a = reshape (1:8, 2, 2, 2) # Create 3-D array | 154 a = reshape (1:8, 2, 2, 2) # Create 3-D array |
154 a = | 155 a = |
155 | 156 |
156 ans(:,:,1) = | 157 ans(:,:,1) = |
157 | 158 |
167 a(2,1); # Case (m < n), idx within array: | 168 a(2,1); # Case (m < n), idx within array: |
168 # equivalent to a(2,1,1), ans = 2 | 169 # equivalent to a(2,1,1), ans = 2 |
169 a(2,4); # Case (m < n), idx outside array: | 170 a(2,4); # Case (m < n), idx outside array: |
170 # Dimension 2 & 3 folded into new dimension of size 2x2 = 4 | 171 # Dimension 2 & 3 folded into new dimension of size 2x2 = 4 |
171 # Select 2nd row, 4th element of [2, 4, 6, 8], ans = 8 | 172 # Select 2nd row, 4th element of [2, 4, 6, 8], ans = 8 |
172 @end group | |
173 @end example | 173 @end example |
174 | 174 |
175 One advanced use of indexing is to create arrays filled with a single | 175 One advanced use of indexing is to create arrays filled with a single |
176 value. This can be done by using an index of ones on a scalar value. | 176 value. This can be done by using an index of ones on a scalar value. |
177 The result is an object with the dimensions of the index expression | 177 The result is an object with the dimensions of the index expression |