[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Global variables with Octave
From: |
Mats Jansson |
Subject: |
Re: Global variables with Octave |
Date: |
Thu, 24 Aug 2000 10:13:01 +0200 |
Eric Bouyoux wrote:
>
> Hi,
>
> I have a problem with variables in functions:
>
> This works :
>
> function y = toto (x)
> a = 5;
> b = 20;
> y = a*x+b;
> endfunction
>
> for x = 0:1:20
> printf("Result = %fÜn",toto(x));
> endfor
>
> This does not work :
>
> global a = 5;
> global b = 20;
> function y = toto (x)
> y = a*x+b;
> endfunction
>
> for x = 0:1:20
> printf("Result = %fÜn",toto(x));
> endfor
>
> error: `a' undefined near line 2 column 5
> error: evaluating expression near line 2, column 5
> error: evaluating binary operator `*' near line 2, column 6
> error: evaluating binary operator `+' near line 2, column 8
> error: evaluating assignment expression near line 2, column 3
> error: called from `toto'
> error: evaluating argument list element number 2
>
> Is anyone able to help me.
>
> Regards.
>
> Eric Bouyoux.
You have to tell the function to use the global variables:
global a = 5;
global b = 20;
function y = toto (x)
global a
global b
y = a*x+b;
endfunction
Regards,
Mats
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------