|
Hi James,
the code is this:
(part of my code to char)
const char path[] = "c:\\dataopen";
mxArray *path_C;
path_C = mxCreateString(path); (wrongly copied early from my real code.. sorry :( )
memcpy(mxGetPr(path_C),path, sizeof(char));
mlfFoo(1, &y_ptr, path_C);
I tested without memcpy....I thought i need memcpy... thanks :D!
Regarding my matrix, I follow the matlab example that they have:
//matrix data
double *data = new double [2000];
double *y;
//all my data is read from a file and stored in the matrix "data".
// data will be data=[1 2 3 4 5 6 7 8 ... 2000]
/* Call the MCR and library initialization functions */
if( !mclInitializeApplication(NULL,0) )
{
fprintf(stderr, "Could not initialize the application.\n");
exit(1);
}
if (!foolibInitialize())
{
fprintf(stderr,"Could not initialize the library.\n");
exit(1);
}
mxArray *y_ptr=NULL;
mxArray *Cdata;
//I want to organize my data in 4 columns
Cdata = mxCreateDoubleMatrix(500,4,mxREAL);
memcpy(mxGetPr(Cdata),data, 2000*sizeof(double));
//my lib from matlab, I'll perform a bunch of operations with each column of my data
//it's important to have the 500 1st rows in the 1st column, the 2nds 500 rows
//in the second column, and so on
mlfFoo(1, &y_ptr, dataC);
foolibTerminate();
mxDestroyArray(y_ptr);
mxDestroyArray(Cdata);
I don't know if this is enough to you to help me, if you need something more, please say.
Thanks a lot :)!
MatlabFCT NG <matfctng@gmail.com> wrote in message <93da80a6-5860-4253-a811-af53a55ec17e@u7g2000yqm.googlegroups.com>...
> Hi,
>
> following the suggestion of Bruno I found the solution to my char
> array,
>
> (part of my code)
> const char path[] = "c:\\dataopen";
> mxArray *path_C;
> caminho_C = mxCreateString(path);
> memcpy(mxGetPr(path_C),path, sizeof(char));
>
> mlfFoo(1, &y_ptr, path_C);
>
> Unfortunately I don't have any hint regarding the matrix input :(,,,
> Can anyone give me some suggestion/hint to follow?
>
> Thank you all
>
> mxDestroyArray(path_C );
>
>
> On 21 Nov, 16:23, MatlabFCT NG <matfc...@gmail.com> wrote:
> > Hi Bruno,
> >
> > thanks for your answer :). I really don't know what's happening :(..
> > I follow the example for C libray (Matlab help). The only difference
> > is they have a square matrix... Maybe I'm not allocating properly my
> > matrix (Cdata = mxCreateDoubleMatrix(500,4,mxREAL);)...
> >
> > About my char array, i try the following code:
> >
> > char *path;
> > path= "C:\dataopen"
> > ? ? ? ? int ndim = 2;
> > ? ? ? ? int dims[2];
> > ? ? ? ? dims[0] = 1;
> > ? ? ? ? dims[1] = 12;
> >
> > ? ? ? ? path_C = mxCreateCharArray(ndim, (const mwSize *)&dims);
> > memcpy(mxGetPr(path_C),path, 12*sizeof(char));
> >
> > Althougth the data is no being read correctly to matlab. Is this the
> > right way to do to a char variable?
> >
> > Thanks for you help :)
> >
> > On 21 Nov, 06:56, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote:
> >
> > > MatlabFCT NG <matfc...@gmail.com> wrote in message <cabe1e40-6bd5-4096-9839-9de1d24c4...@o10g2000yqa.googlegroups.com>...
> >
> > > > First Question: I don't have any problem in the matrix [10*1], however
> > > > in the large matrix the data is wrongly transfer to the dll matlab,
> > > > example:
> >
> > > > input data: data =
> > > > |1 2 3 4 |
> > > > |5 6 7 8 |
> > > > |9 10 11 12|
> > > > |13 14 15 16|
> > > > |17 (...) |
> >
> > > > inside dll (matlab)
> > > > |1 5 9 13|
> > > > |17 (...) |
> >
> > > > Is there a way to fix this? I would like to avoid performing double
> > > > transpose in the dll....
> >
> > > Something is not right in your example. Inside Matlab it should be
> >
> > > | 1 ...
> > > ? 2 ...
> > > ? 3 ...
> > > ? 4 ...
> > > ? 5 ... |
> >
> > > Because Matlab data organized column wise.
> >
> > > > Second question: How can I transfer a char array from C++ to the DLL?
> >
> > > Use mxCreateString(...)
> >
> > > Bruno
|