Blitz logo

Blitz Support :

From: Sam Kaplan (skaplan_at_[hidden])
Date: 2003-05-14 12:08:02


Hello,

Perhaps this isn't the answer you're looking for, but here is a quick
and dirty solution:

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[])
{
Array<double,2> A;
double *pr;
int i,j,m,n;

// matlab --> blitz
m = mxGetM(prhs[0]);
n = mxGetN(prhs[0]);

A.resize(m,n);
  
pr = (double *)mxGetPr(prhs[0]);

for (j = 0; j < n; j++){
  for (i = 0; i < m; i++)
    A(i,j) = pr[i + m*j];
}
...

// blitz --> matlab
plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL);
pr = (double *)mxGetPr(plhs[0]);
for (j = 0; j < n; j++){
  for (i = 0; i < m; i++)
    pr[i + j*m] = A(i,j);
}
pr = 0;
}

I hope this wasn't totally useless.

Sam

On Wed, 2003-05-14 at 05:29, Oliver Lange wrote:
> Hi,
>
> has anyone written a conversion routines from
> Blitz Array's to the Matlab mxArray Structure?
>
> I want to use
> Blitz-driven Routines as mexFunctions
> that means i get input from Matlab as mxArray have
> to convert to Blitz++, do calculations and convert
> back into mxArray - Format before passing back the results to
> matlab.
>
> Olli
>
>