help-octave
[Top][All Lists]
Advanced

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

Re: problem about returning a matrix


From: Alain Baeckeroot
Subject: Re: problem about returning a matrix
Date: Tue, 7 Apr 2009 15:39:48 +0200
User-agent: KMail/1.9.9

Le 07/04/2009 à 13:54, ozalpi a écrit :
> 
> Hi, we want to develop a function that returns a matrix but we couldn't be
> able to convert this matrix or more simply a list to an octave_value_list to
> return the result. Only the first element of the matrix is seen from octave.
> Can anyone help us about this problem we have?
> 
> Our code segment is:
> 
> #include <octave/oct.h>
> ...
> ...
> DEFUN_DLD(...)
> {
> octave_value_list retval;
> for(int i = 0; i < row1; i++)
> {
>       for(int j = 0; j < column1; j++)
>       {
>               out >> x;
>               retval(i*column1 + j)=octave_value(x);
>       }
> }
> return retval;
> }


i have this to return a Matrix:
 ...
 #include <octave/oct.h>
 ...
 ...
 DEFUN_DLD(...)
 {
    ....

    Matrix X(n, k);             // now we know there's data, so let's assign it

    for (long i = 0; i < n; i++)        // loop over all elements, and convert 
to doubles
        for (long j = 0; j < k; j++)
            sscanf(PQgetvalue(res, i, j), "%lf", &X(i, j));

    /* cleanup and close the connection to the database */
    ...

    retval(0) = X;              // set the return vector and
    return retval;     
 }      




reply via email to

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