Discussion:
Returning more than one argument from OCT file
(too old to reply)
j***@gmail.com
2011-01-31 15:57:17 UTC
Permalink
Hi all,

I have been looking for an answer to a very simple question:

How do I return more than one argument from an octave C++ function.

The following is a simple example of a function that returns a single
argument. How do I modify it to return a 2nd argument of different
type?

#include <octave/oct.h>

DEFUN_DLD(matMult,args, , "Test function.")
{
ComplexMatrix a(args(0).complex_matrix_value());

Matrix b(args(1).matrix_value());

ColumnVector c(args(2).vector_value());

return octave_value(a*2);
}

I would be inclined to create a octave_value_list object that contains
more than one return value. But it is not clear how to do that. The
constructor for octave_value_list can accept an Array. But how to
create an array? The array constructor requires an array to create...

Thanks to anyone willing to rescue me here.

Jay
j***@gmail.com
2011-01-31 17:53:00 UTC
Permalink
Post by j***@gmail.com
Hi all,
How do I return more than one argument from an octave C++ function.
The following is a simple example of a function that returns a single
argument.  How do I modify it to return a 2nd argument of different
type?
#include <octave/oct.h>
DEFUN_DLD(matMult,args, , "Test function.")
{
   ComplexMatrix a(args(0).complex_matrix_value());
   Matrix b(args(1).matrix_value());
   ColumnVector c(args(2).vector_value());
   return octave_value(a*2);
}
I would be inclined to create a octave_value_list object that contains
more than one return value.  But it is not clear how to do that.  The
constructor for octave_value_list can accept an Array.  But how to
create an array? The array constructor requires an array to create...
Thanks to anyone willing to rescue me here.
Jay
I solved my own problem by looking at some code in the octave
toolboxes:

octave_value_list retval;

retval(0) = a;
retval(1) = b;

return retval;

Can't figure out why this works, looking at doxygen api, but it does
work.

Maybe this will be helpful for someone.

Loading...