From help-request at octave dot org Mon May 24 08:39:02 2004 Subject: RE: global variables From: "Hall, Benjamin" To: "'Dan Eriksson'" , octave help mailing list Date: Mon, 24 May 2004 09:31:18 -0400 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C44193.655D0750 Content-Type: text/plain; charset="iso-8859-1" To get your function to recognize the global x -- as opposed to creating its own local variable x, you must first tell it so. function test global x y = x + 1 end should do what you want -----Original Message----- From: Dan Eriksson [mailto:dan dot eriksson at akustikforum dot se] Sent: Monday, May 24, 2004 9:10 AM To: octave help mailing list Subject: global variables Hi! I have version 2.1.50 and can't bring global variables into functions. This is what I get: global x = 1 isglobal("x") ans = 1 function test isglobal("x") y=x+1 endfunction test ans = 0 error: 'x' undefined Any ideas? Best regards Dan Eriksson ___________________________________________________ Dan Eriksson Akustikforum AB Stampgatan 15 416 64 Gothenburg SWEDEN tel: +46 31 156200 fax: +46 31 150580 www.akustikforum.se ------_=_NextPart_001_01C44193.655D0750 Content-Type: text/html; charset="iso-8859-1"
To get your function to recognize the global x -- as opposed to creating its own local variable x, you must first tell it so.
 
function test
global x
y = x + 1
end
 
should do what you want
-----Original Message-----
From: Dan Eriksson [mailto:dan dot eriksson at akustikforum dot se]
Sent: Monday, May 24, 2004 9:10 AM
To: octave help mailing list
Subject: global variables

Hi!
 
I have version 2.1.50 and can't bring global variables into functions. This is what I get:
 
global x = 1
isglobal("x")
ans = 1

function test
isglobal("x")
y=x+1
endfunction
 
test
ans = 0
error: 'x' undefined
 
 
 
Any ideas?
 
Best regards
Dan Eriksson
 
 
___________________________________________________
Dan Eriksson
Akustikforum AB
Stampgatan 15
416 64 Gothenburg
SWEDEN
tel: +46 31 156200
fax: +46 31 150580
www.akustikforum.se
------_=_NextPart_001_01C44193.655D0750-- ------------------------------------------------------------- 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 -------------------------------------------------------------