comparison doc/interpreter/numbers.txi @ 4476:b7360f8eb035

[project @ 2003-07-30 17:17:21 by jwe]
author jwe
date Wed, 30 Jul 2003 17:17:21 +0000
parents cef48c4b902d
children 7afd4bf05aa8
comparison
equal deleted inserted replaced
4475:15c739d0c13c 4476:b7360f8eb035
150 13, of course). 150 13, of course).
151 151
152 Inside the square brackets that delimit a matrix expression, Octave 152 Inside the square brackets that delimit a matrix expression, Octave
153 looks at the surrounding context to determine whether spaces and newline 153 looks at the surrounding context to determine whether spaces and newline
154 characters should be converted into element and row separators, or 154 characters should be converted into element and row separators, or
155 simply ignored, so commands like 155 simply ignored, so an expression like
156
157 @example
158 [ linspace (1, 2) ]
159 @end example
160
161 @noindent
162 and
163 156
164 @example 157 @example
165 @group 158 @group
166 a = [ 1 2 159 a = [ 1 2
167 3 4 ] 160 3 4 ]
184 [ 1 -1 ] 177 [ 1 -1 ]
185 @end example 178 @end example
186 179
187 @noindent 180 @noindent
188 the @samp{-} is treated as a unary operator and the result is the 181 the @samp{-} is treated as a unary operator and the result is the
189 vector @code{[ 1, -1 ]}. 182 vector @code{[ 1, -1 ]}. Similarly, the expression
190 183
191 Given @code{a = 1}, the expression 184 @example
185 [ sin (pi) ]
186 @end example
187
188 @noindent
189 will be parsed as
190
191 @example
192 [ sin, (pi) ]
193 @end example
194
195 @noindent
196 and will result in an error since the @code{sin} function will be
197 called with no arguments. To get around this, you must omit the space
198 between @code{sin} and the opening parenthesis, or enclose the
199 expression in a set of parentheses:
200
201 @example
202 [ (sin (pi)) ]
203 @end example
204
205 Whitespace surrounding the single quote character (@samp{'}, used as a
206 transpose operator and for delimiting character strings) can also cause
207 confusion. Given @code{a = 1}, the expression
192 208
193 @example 209 @example
194 [ 1 a' ] 210 [ 1 a' ]
195 @end example 211 @end example
196 212
197 @noindent 213 @noindent
198 results in the single quote character @samp{'} being treated as a 214 results in the single quote character being treated as a
199 transpose operator and the result is the vector @code{[ 1, 1 ]}, but the 215 transpose operator and the result is the vector @code{[ 1, 1 ]}, but the
200 expression 216 expression
201 217
202 @example 218 @example
203 [ 1 a ' ] 219 [ 1 a ' ]
209 @example 225 @example
210 error: unterminated string constant 226 error: unterminated string constant
211 @end example 227 @end example
212 228
213 @noindent 229 @noindent
214 because to not do so would make it impossible to correctly parse the 230 because to not do so would cause trouble when parsing the valid expression
215 valid expression
216 231
217 @example 232 @example
218 [ a 'foo' ] 233 [ a 'foo' ]
219 @end example 234 @end example
220 235
221 For clarity, it is probably best to always use commas and semicolons to 236 For clarity, it is probably best to always use commas and semicolons to
222 separate matrix elements and rows. It is possible to enforce this style 237 separate matrix elements and rows.
223 by setting the built-in variable @code{whitespace_in_literal_matrix} to
224 @code{"ignore"}.
225
226 @DOCSTRING(whitespace_in_literal_matrix)
227 238
228 @DOCSTRING(warn_separator_insert) 239 @DOCSTRING(warn_separator_insert)
229 240
230 When you type a matrix or the name of a variable whose value is a 241 When you type a matrix or the name of a variable whose value is a
231 matrix, Octave responds by printing the matrix in with neatly aligned 242 matrix, Octave responds by printing the matrix in with neatly aligned