[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with column specification in matrices

From: John W. Eaton
Subject: problem with column specification in matrices
Date: Thu, 31 Oct 2002 13:18:06 -0600

On 31-Oct-2002, Mike Miller <address@hidden> wrote:

| What's the deal with this?  In command 3, you can see that octave messes
| up when I do not include a comma between columns of the matrix.  A comma
| seems not to be required, so this seems like a bug.  It does it at least
| under 2.1.36.

You are hitting a variation of the problem described in the Numeric
Data types/Matrices section of the Octave manual:

     Inside the square brackets that delimit a matrix expression, Octave
  looks at the surrounding context to determine whether spaces and newline
  characters should be converted into element and row separators, or
  simply ignored, so commands like

       [ linspace (1, 2) ]


       a = [ 1 2
             3 4 ]

  will work.  However, some possible sources of confusion remain.  For
  example, in the expression

       [ 1 - 1 ]

  the `-' is treated as a binary operator and the result is the scalar 0,
  but in the expression

       [ 1 -1 ]

  the `-' is treated as a unary operator and the result is the vector `[
  1, -1 ]'.

     Given `a = 1', the expression

       [ 1 a' ]

  results in the single quote character `'' being treated as a transpose
  operator and the result is the vector `[ 1, 1 ]', but the expression

       [ 1 a ' ]

  produces the error message

       error: unterminated string constant

  because to not do so would make it impossible to correctly parse the
  valid expression

       [ a 'foo' ]

In an expression like

  [n (1+1./n).^n]

should that be interpreted as two expressions

  [n, (1+1./n).^n]

or as one, with n indexed by the second expression (that's what you'd
get without the square brackets).

IMHO, it was bad design for Matlab to make whitespace magic inside the
square brackets.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]