help-octave
[Top][All Lists]
Advanced

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

Re: Octave C++ classes


From: Paul Thomas
Subject: Re: Octave C++ classes
Date: Thu, 08 Jul 2004 19:37:10 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Tomasso,

Just to expand on David's reply:

#include <octave/oct.h>
DEFUN_DLD(revs,args,nargout," b = revs( a )\n b is the index reverse of
matrix a\
\n\nTest with b = revs( [1:5]'*[1:5] )")
{
 Matrix vin( args(0).matrix_value());
idx_vector idxc( Range( double( vin.cols() ) , 1.0 , -1.0 ) ); idx_vector idxr( Range( double( vin.rows() ) , 1.0 , -1.0 ) ); return octave_value( Matrix( vin.index( idxr , idxc ) ) );
}

Does what you are trying to do.  This one inverts row and column orders.  To
reverse a vector;
{
 ColumnVector vin( args(0).vector_value());
idx_vector idx( Range( double( vin.rows() ) , 1.0 , -1.0 ) ); return octave_value( Column_Vector( vin.index( idx ) ) );
}

does the trick.

Note constructors
    Range( double begin , double limit , double increment )
    idx_vector( Range )
    Matrix( Array2<double> )  (NB.  vin.index( i , j) returns Array2 )

and function
    Matrix::index( idx_vector , idx_vector )

Best regards

Paul T

David Bateman wrote:

Check out the code in do_index_op and assign in ov-base-mat.cc where
the class index_vector is used. The value of index_vector can be a
":" (flagged as a magic colon) or a range. This should do pretty much what you want.

As for the octave -> c++ compiler check out

http://www.stud.tu-ilmenau.de/~rueckn/

which is experimental..

D.

According to Tommaso Cucinotta <address@hidden> (on 07/08/04):
Hi,

I'd like to know if there is a "natural" way to
translate something like

 X_rev = X(length(X):-1:1)

(or making other more advanced row or column selections,
like 1:2:9 ecc...) into C++ using the octave classes.

It seems to me the Range class is what I need to use, but
I cannot figure out how to index a vector or matrix with a
Range.

Also, I would like to know if anybody ever wrote an Octave to C++
translator.

Many thanks in advance,

        Tommaso.



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





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