help-octave
[Top][All Lists]
Advanced

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

Re: Whitespace question, [zeros (1, 2), ones (1, 2)]


From: Paul Roberts
Subject: Re: Whitespace question, [zeros (1, 2), ones (1, 2)]
Date: Sat, 5 Nov 2005 17:02:18 -0800

Hi Steve,

I think that the problem in this case is the way octave parses array
declarations. In an array declaration, whitespace is treated as an
element delimiter. For example:

>>> a = [1 2 3]
a =

  1  2  3

So when you try:

>>> [ones (1,2)]

octave treats it like

>>> [ones,(1,2)]


I checked, and both expressions give the same syntax error that you
mentioned above. So the whitespace between function name and arguments
won't work inside of an array declaration.

I have always put the function name right before the argument list
with no whitespace and it  has never caused any problems going between
Octave and Matlab, although I have only been using Octave for 6
months.


Paul


Paul


On 11/5/05, Steve C. Thompson <address@hidden> wrote:
> Hi,
>
> In my continuing pursuit in figuring out how to write programs
> that don't suck, and are readable and consistent, I've ran into a
> whitespace problem.  A toy example:
>
>   octave:1> ones (1, 2)
>   ans =
>
>     1  1
>
>   octave:2> zeros (1, 2)
>   ans =
>
>     0  0
>
>   octave:3> [ones (1, 2), zeros (1, 2)]
>   parse error:
>
>     syntax error
>
>   >>> [ones (1, 2), zeros (1, 2)]
>                     ^
>
>   octave:3> [ones(1, 2), zeros(1, 2)]
>   ans =
>
>     1  1  0  0
>
>
> So, the whitespace in `[ones (1, 2), zeros (1, 2)]' causes
> problem.  Should I just forget about whitespace between functions
> and ()s?  I personally like the whitespace; I think that it aids
> in readability.  However, I want to stick to a rule that will
> work unconditionally.  (And, for my current collaboration
> efforts, I require strict MATLAB compatibility [sigh].)
>
> Thanks for any advice and suggestions you might have.
>
> Steve
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>
>



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

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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