[Top][All Lists]

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

Re: unexpected syntax error when defining a global variable?

From: Nicholas Jankowski
Subject: Re: unexpected syntax error when defining a global variable?
Date: Tue, 21 Apr 2015 13:19:04 -0400

ok, thanks. I saw the help said you could declare global and assign in a single command, but it does state "A global variable may only be initialized once in a global statement..."  as the only limitation. I guess it's related.

FYI - just tried on a friend's PC in ML and got a similar error (Error: Unbalanced or unexpected parenthesis or bracket.) so that behavior is compatible, but also noticed that ML doesn't allow you to do simple assignment at all.

ML (R2014b):
global p_i = 5
Error: The _expression_ to the left of the equals sign is not a valid target for an assignment.

Octave (3.8.2)
>> global p_i=5
>> p_i
p_i =  5

On Tue, Apr 21, 2015 at 12:51 PM, Julien Bect <address@hidden> wrote:
Le 21/04/2015 18:43, Nicholas Jankowski a écrit :
simple example:

>> segments = 5;
>> p_i(1:segments+1)= 0
p_i =

   0   0   0   0   0   0


>> segments = 5;
>> global p_i(1:segments+1)= 0
parse error:
  syntax error
>>> global p_i(1:segments+1)= 0
if the characters spacing is messed up, it's pointing to the (

Is that supposed to happen? I didn't think a global designation was supposed to change anything with syntax. bug?

Nick J.

I don't think you can declare a global and use indexing on it at the same time. Try in two steps:

global p_i
p_i(1:segments+1)= 0;


global p_i
p_i = zeros (1, segments + 1);

Help-octave mailing list

reply via email to

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