help-octave
[Top][All Lists]
Advanced

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

Global array variable from an OCT file example


From: mpender
Subject: Global array variable from an OCT file example
Date: Wed, 8 Jan 2014 21:49:27 -0800 (PST)

Could someone please provide a good example of updating the elements of a
global array variable from an OCT file?  I've found examples in the octave
documentation showing how to access global variables from OCT files
(http://www.gnu.org/software/octave/doc/interpreter/Accessing-Global-Variables-in-Oct_002dFiles.html#Accessing-Global-Variables-in-Oct_002dFiles)
and on Sourceforge
(http://octave.sourceforge.net/coda/c58.html#ex-matpow-high-level), but
nothing that shows how to write the value of an array element in an existing
global variable.

A normal best practice in Octave is to reserve the memory I need for my
arrays ahead of time.  At the moment, I'm using a Matrix constructor and
then assigning the Matrix variable to the global variable, which has the
effect of requesting fresh memory for the array every time I call my OCT
file instead of preallocating memory.  

This is an example of what I'm doing to return data in a global variable
right now:
...
Matrix tmp1 (parm1, parm2);
{
  // operations go here to set various elements in the array
}
set_global_value ("POPULATION", tmp1);
...

The space for the global variable POPULATION has been reserved before my OCT
file is called, so I really only want to modify the specific elements that
need to be modified.  I don't want to copy the whole array in to the OCT
file and back out again.  But I'm struggling with trying to find the right
syntax to access and set specific elements.  I would love to see an example.  

If I use get_global_value does it return a pointer to the global so that the
original can be modified in memory, or does it just make a copy of the
global and operations are performed on the copy?  I'm essentially wondering
whether these parameters are passed by value or by reference, or according
to some other scheme?

Thanks, Mike



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Global-array-variable-from-an-OCT-file-example-tp4660831.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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