problem about returning a matrix

View: New views
5 Messages — Rating Filter:   Alert me  

problem about returning a matrix

by ozalpi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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

Re: problem about returning a matrix

by Carlo de Falco-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 7 Apr 2009, at 13:54, ozalpi wrote:

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


this function, as it stands, returns each element of the matrix as a  
separate variable..
I guess what you want to do is rather something like

#include <octave/oct.h>
...
...
DEFUN_DLD(...)
{
Matrix A;

for(int i = 0; i < row1; i++)
{
        for(int j = 0; j < column1; j++)
        {
                out >> x;
                A(i*column1 + j)=x;
        }
}
return octave_value(A);
}

c.
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: problem about returning a matrix

by Alain Baeckeroot :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: problem about returning a matrix

by Carlo de Falco-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/4/7 Carlo de Falco <carlo.defalco@...>
>
> this function, as it stands, returns each element of the matrix as a separate variable..
> I guess what you want to do is rather something like

<...>

Actually you probably want:

>
> #include <octave/oct.h>
> ...
> ...
> DEFUN_DLD(...)
> {
> Matrix A(row1, column1
> );
>
> for(int i = 0; i < row1; i++)
> {
>        for(int j = 0; j < column1; j++)
>        {
>                out >> x;
>                A(i, j)=x;
>        }
> }
> return octave_value(A);
> }
>

 c.

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: problem about returning a matrix

by ozalpi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

that helps me thank you very much :)





Carlo de Falco-2 wrote:
2009/4/7 Carlo de Falco <carlo.defalco@gmail.com>
>
> this function, as it stands, returns each element of the matrix as a separate variable..
> I guess what you want to do is rather something like

<...>

Actually you probably want:

>
> #include <octave/oct.h>
> ...
> ...
> DEFUN_DLD(...)
> {
> Matrix A(row1, column1
> );
>
> for(int i = 0; i < row1; i++)
> {
>        for(int j = 0; j < column1; j++)
>        {
>                out >> x;
>                A(i, j)=x;
>        }
> }
> return octave_value(A);
> }
>

 c.

_______________________________________________
Help-octave mailing list
Help-octave@octave.org
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave