|
Hi,
in the mex file you shouldn't use mexCallMATLAB, but
just assign values to the array, something like
/* copy the array */
pOut[0] = mxDuplicateArray(pIn[0]);
/* get the pointer */
double *ptr = mxGetPr(pOut[0]);
/* do the assignment: */
ptr[0] = 1;
Titus
"Nikolai Yu. Zolotykh" <zny@uic.nnov.ru> schrieb im Newsbeitrag
news:ef45ef9.-1@webcrossing.raydaftYaTP...
> mexCallMATLAB is slower.
>
> Let
> A=zeros(1000);
>
> I want to do an assignment
>
> A(1,1) = 1
>
> In MATLAB environment it requires 0.000027 seconds:
>
> tic;A(1,1)=1;toc;
> Elapsed time is 0.000027 seconds.
>
> The following mexFucntion does the same:
>
> /* myassignment.c */
> #include "mex.h"
> void mexFunction(int nOut, mxArray *pOut[],
> int nIn, const mxArray *pIn[])
> {
> mexCallMATLAB(1, pOut, 3, pIn, "subsasgn");
> }
>
> mex myassignment.c
> A=zeros(1000);
> S.type = '()';
> S.subs = {1,1};
> A=myassignment(A, S, 1);
> A(1,1)
>
> ans =
>
> 1
>
> But now the time requiered is 0.020915 seconds:
>
> tic;A=myassignment(A, S, 1);toc;
> Elapsed time is 0.020915 seconds.
>
> It is too slow!
>
> I suppose in mexCallMATLAB MATLAB copies matrices and does not make
> the subscript assignment in-place!
>
> Any suggestions are welcome.
|