help-octave
[Top][All Lists]
Advanced

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

Re: varargout form a DLD function


From: Søren Hauberg
Subject: Re: varargout form a DLD function
Date: Thu, 29 Jan 2004 17:54:31 +0100
User-agent: Internet Messaging Program (IMP) 4.0-cvs

Hi
I'm new to liboctave (and octave), but the way I understand it nargout tells you
the number og requested output arguments.
If you (in octave) do:
[a b c] = test_arg()
then nargout will be 3.
So just change your code to:

    octave_value_list retval;
    for(int i=0;i<nargout;i++) retval(i)=i;
    return retval;

Then things should work (if I uinderstood your problem correctly)

Soren Hauberg

Citat Shai Ayal <address@hidden>:

> Hi all,
>
> I am trying to return a variable number of arguments from a DLD function
>
> //-------------------------------------------------
> #include "oct.h"
> DEFUN_DLD (test_arg, args, nargout,"")
> {
>    octave_value_list retval;
>
>    for(int i=0;i<5;i++) retval(i)=i;
>
>    nargout = 5;
>    return retval;
> }
> //-------------------------------------------------
>
>
> however, I cannot recover these arguments at the command line:
>
> GNU Octave, version 2.1.50 (i686-pc-linux-gnu).
> octave:1> test_arg()
> ans = 0
> octave:2> a{:}=test_arg()
> a =
> {
>    [1,1] = 0
> }
> octave:3> b=test_arg()
> b = 0
> octave:4> [a,b,c]=test_arg()
> a = 0
> b = 1
> c = 2
>
> Note that if I know the number of arguments I can get them as in line 4.
> but what if I don't know beforehand ? Is there something similar to
> varargin{:} for output arguments ?
>
>       Shai
>
>


--
Knibling, det gode gamle håndværk med "pinde", er rigtig kommet på mode igen



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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