help-octave
[Top][All Lists]
Advanced

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

using a global variable as default argument


From: Erik Leunissen
Subject: using a global variable as default argument
Date: Sun, 23 Mar 2014 17:08:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

Hi all,

Is there a way to use a global variable as a default argument?

I couldn't get it to work (see below for exercise), but maybe I overlooked something.

Thanks in advance for any clarification,

Erik Leunissen.
--



-- script file tst.m --
function rv = f(v=pi)
    return v;
endfunction
--

> tst
> rv()
ans =  3.1416


OK, that works. However, the following doesn't:

-- script file tst.m --
global myconst = 1.2345;

function rv = f(v=myconst)
    return v;
endfunction
--

> tst
> rv()
error: 'myconst' undefined near line 3 column 19




reply via email to

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