From help-request at octave dot org Wed Jun 2 08:39:26 2004 Subject: Re: A question about programming using dynamically linked function From: Paul Thomas To: jiaguo at uiuc dot edu Cc: help at octave dot org Date: Wed, 02 Jun 2004 15:38:33 +0200 Find below a slightly different approach to David's. Like David the Array function fortran_vec() is used to point to the first member in the complexMatrix. However, my example uses the C++ standard library complex, rather than the octave Complex. I have commented out a transpose that operates directly on the complex matrices and replaced it in the next line with the same operation using complex pointers. Best regards Paul T #include #include #include typedef std::complex dComplex; DEFUN_DLD (complexdemo, args, , "Demonstrate fortran_vec for complex \n\n\ transpose_of_x=complexdemo(x) \n") { if ( args.length() != 1 ) { error("this version of matrixdemo omly takes one argument"); return octave_value( 0 ); } ComplexMatrix xin1( args(0).complex_matrix_value() ); int ir = xin1.rows(); int ic = xin1.cols(); ComplexMatrix xout1(ic,ir); dComplex *pin1 = xin1.fortran_vec(); dComplex *pout1 = xout1.fortran_vec(); for (int ir1 = 0 ; ir1 < ir ; ir1++) for (int ic1 = 0 ; ic1 < ic ; ic1++) { // xout1(ic1,ir1) = xin1(ir1,ic1); //transpose using Matrices pout1[ic1 + ir1*ic] = pin1[ir1 + ic1*ir]; //transpose using pointers } return octave_value( xout1 ); } jiaguo at uiuc dot edu wrote: >Hi > >I am writing dynamically linked functions. In my function, I >need to copy the data from a complex matrix (in octave_value >type) to a double buffer. I was wondering if there is a way to >find a pointer to the real data in the complex matrix (in >octave_value type), so that I can use memcpy to copy it to my >own buffer. The similar function can be found in MATLAB which >is mxGetPr. Does Octave have similar functions like mxGetPr? > >Thanks a lot! > >Jia >__ > >Friends are angels > sent down to earth > to have good days and > to help us find our way... > > > >------------------------------------------------------------- >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 -------------------------------------------------------------