help-octave
[Top][All Lists]
Advanced

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

Re: doubts about functions declared in parse.h ...


From: Geraint Paul Bevan
Subject: Re: doubts about functions declared in parse.h ...
Date: Fri, 11 Mar 2005 17:35:50 +0000
User-agent: Mozilla Thunderbird 0.7.1 (X11/20040715)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alberto Francisco Martin Huertas wrote:

| I would like the following behaviour in a Octave session:
|
| octave:1> A=1
| A = 1
| octave:2> example_function()
| ans = 3
| octave:2> A
| A = 1
|
| Thanks for your help, Alberto.


It is normal Octave behaviour to limit the scope of variables to the
calling function,


assignment.m:
A = 3


example_function.m:
function retval = example_function ()
~  assignment;
~  retval = A;
endfunction


octave> A = 1
A = 1
octave> example_function
A = 3
ans = 3
octave> A
A = 1


However, there is no way (as far as I am aware) of using a *script* such
as "assignment.m" to assign values to variables within a DLD. The Octave
environment is separate from the C++ dynamic function.

If you need to get values from an m-file, you could create a function
which returns them,


assign_A.m:
function retval = assign_A ()
A = 3   # you could call assignment.m here, instead
retval = A;
endfunction


example_function.cc:
#include <octave/oct.h>
#include <octave/parse.h>
DEFUN_DLD(example_function, args, , "demo")
{
~  octave_value_list retval;
~  octave_value A = feval("assign_A")(0).double_value();
~  retval(0) = A;
~  return retval;
}


octave> A = 1
A = 1
octave> example_function
A = 3
ans = 3
octave> A
A = 1


- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iEYEARECAAYFAkIx1vUACgkQcXV3N50QmNNr/QCeKE5A7nK/RJgAgdc95zvaeXba
jLAAmwSpbIy47sQZl1i3ggGRwzh0ea3F
=Dc9/
-----END PGP SIGNATURE-----



-------------------------------------------------------------
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]