Combining NR C++ and Matlab


DROPlet
12-01-2004, 07:03 AM
Hi,
I am trying to use amoeba for multidim optimization. Function to be optimized is written in Matlab , and compiled into library using Matlab Compiler.
The problem is that surely input and output to/from this Matlab-written function belongs not to NRVec class...
I do not want to use different classes in general instead of NR-based ones... so not sure if I have to write the wrapper-class replacement...

What's the best solution here?

I would appreciate your advice!

Best,
GV:D

Kevin Dolan
12-31-2004, 02:25 PM
Well, you can always get a pointer to the first element of the internal array of an NRVec by taking the address of the first element.

NRVec<double> x(N);
double *array = &(x[0]);

Then you can pass array to any function expecting a normal array of doubles. If the Matlab functions allocate their own memory, or require some special type of storage type, then things are more difficult.

Kevin

b4codes
05-07-2006, 09:47 PM
As far as I aware of Matlab functions does not require special storage type. though you may like to check it out at kluid ( http://www.kluid.com ), its a dedicated Matlab forum.

: ]


Well, you can always get a pointer to the first element of the internal array of an NRVec by taking the address of the first element.

NRVec<double> x(N);
double *array = &(x[0]);

Then you can pass array to any function expecting a normal array of doubles. If the Matlab functions allocate their own memory, or require some special type of storage type, then things are more difficult.

Kevin