Returning more than one argument from OCT file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning more than one argument from OCT file

jayt0808

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 thing.  But it is not clear how to do that.

Thanks to anyone willing to rescue me here.

Jay

--
View this message in context: http://octave.1599824.n4.nabble.com/Returning-more-than-one-argument-from-OCT-file-tp3249014p3249014.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Returning more than one argument from OCT file

Jordi Gutiérrez Hermoso
On 31 January 2011 09:52, jayt0808 <[hidden email]> wrote:
> How do I return more than one argument from an octave C++ function.

Return an octave_value_list object from the DEFUN_DLD. You can resize
it with the resize() member function and it's zero-based indexable
with operator().

HTH,
- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Returning more than one argument from OCT file

David Bateman-2
In reply to this post by jayt0808
jayt0808 wrote:

> 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 thing.  But it is not clear how to do that.
>
> Thanks to anyone willing to rescue me here.
>
> Jay
>
>  

DEFUN_DLD(matMult,args, , "Test function.")
{
   octave_value_list retval;

   ComplexMatrix a(args(0).complex_matrix_value());

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

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

   retval(2) = octave_value(c);

   retval(1) = octave_value (b)

   retval(0) = octave_value (a);

   return retval;
}


--
David Bateman                                [hidden email]
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave