help-octave
[Top][All Lists]
Advanced

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

About .oct file


From: John W. Eaton
Subject: About .oct file
Date: Thu, 19 Mar 1998 23:22:42 -0600

On 19-Mar-1998, Shiou-Jhy Ja <address@hidden> wrote:

|       I saw a old post in 1997 about recompile .oct file, then calling it
| without restart octave will cause segmentation fault.  It still happened
| for octave2.0.11 on linux with gcc 2.7.2, libc.so.5 .  Is ther a cure? 
| 
|       Also I'm trying to compile some known C routin to .oct file and having
| some question:
| 
| 1) how to extrat data(string, double, ..) from octave command line?
| What I mean is something like:
|   char *str;
|   str=strcpy(arg(0).string_value(),' ');

This doesn't work for a couple of reasons.  First, string_value()
returns a C++ string, not a C string.  If you want to convert it to a
NUL-terminated C string, you need to use

  arg(0).string_value().c_str()

but that returns `const char *', so you can't use that as the first
argument to strcpy.  If you are trying to assing a character string to
an Octave object, just do it:

  octave_value val = "foobar";

There are lots of constructors defined to make things like this
relatively convenient.

| for matrix, I use a silly way to do it:
| 
|    Matrix oct_x=arg(0).matrix_value();
| 
|    int n=oct_x.column();  //assume it's a row vector
| 
|    double *x=new double[n];
| 
|    for (int i=0; i<n; i++)
|        x[i]=oct_x(0,i);
| 
|    then I can call other routin with x

You can extract the data from an Octave Matrix object using

  const double *d = val.matrix_value().data()

This returns all the elements in column-major order.

|       Last question, is there any easy code that can help me learn about
| writing .oct code?

The Octave sources themselves contain lots of examples.  A good place
to start would be the files like src/svd.cc and liboctve/dbleSVD.cc.

jwe



reply via email to

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