From help-octave-request at bevo dot che dot wisc dot edu Mon Jan 8 16:29:33 2001 Subject: Re: accessing workspace variables from .oct module? From: Ben Sapp To: nimrodm at email dot com CC: help-octave at bevo dot che dot wisc dot edu Date: Mon, 08 Jan 2001 15:28:11 -0700 Nimrod Mesika wrote: > > Is reading/writing variables from the workspace of the calling .m > function possible in an .oct module? Yes, it is possible. You will need to know the name of the variable you want to access. Below is a very simple example of doing this. It returns the value stored in a variable named "a" from the workspace. a sample session look like this: octave:1> a = 1 a = 1 octave:2> sr ans = 1 octave:3> a = [1,2,3] a = 1 2 3 octave:4> sr ans = 1 2 3 Source code: ------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include DEFUN_DLD(sr,args,nargout, "Access a variable named \"a\" from the workspace.\n") { std::string symbol_name = "a"; symbol_record *sr = curr_sym_tab->lookup(symbol_name); octave_value tmp = sr->def(); return tmp; } ---------------------------------------------------------------- -- Ben Sapp Los Alamos National Laboratory email: Phone: (505)667-3277 Fax: (505)665-7920 URL: http://www.neutrino.lanl.gov/ -- ------------------------------------------------------------- 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 -------------------------------------------------------------