Thread Subject: Can not use mldivide by mexCallMATLAB

Subject: Can not use mldivide by mexCallMATLAB

From: Renwen Lin

Date: 5 Aug, 2009 07:30:20

Message: 1 of 3

Can not use mldivide by mexCallMATLAB

in matlab r2009a

I have tried several ways , they do not work.

mexCallMATLAB(1, lhs, 2, x, '~/' );

mexCallMATLAB(1, lhs, 2, x,'\');

mexCallMATLAB(1, lhs, 2, x, "\");

mexCallMATLAB(1, lhs, 2, x, "mldivide");

Help me please

Subject: Can not use mldivide by mexCallMATLAB

From: James Tursa

Date: 5 Aug, 2009 17:20:22

Message: 2 of 3

"Renwen Lin" <linrenwen@gmail.com> wrote in message <h5bcec$31s$1@fred.mathworks.com>...
> Can not use mldivide by mexCallMATLAB
>
> in matlab r2009a
>
> I have tried several ways , they do not work.
>
> mexCallMATLAB(1, lhs, 2, x, '~/' );
>
> mexCallMATLAB(1, lhs, 2, x,'\');
>
> mexCallMATLAB(1, lhs, 2, x, "\");
>
> mexCallMATLAB(1, lhs, 2, x, "mldivide");
>
> Help me please

You need to post more code. How are lhs and x declared? How do you create the mxArrays used in x?

James Tursa

Subject: Can not use mldivide by mexCallMATLAB

From: Renwen Lin

Date: 6 Aug, 2009 03:26:02

Message: 3 of 3


Hi James Tursa,

Thanks so much!

I believe that I have solve the current problem on myself, although without finishing the code.

--------------My Purpose -------------------------------------
solve X from A*X = B;
where A and B is supposed to be a page of ND-Array.

--------------My "Collected" Code --------------------------
#include "mex.h"
#include "matrix.h"
#include <stdlib.h>
#include "blas.h"
#include <math.h>
#include <string.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mxArray *lhs[1];
   mxArray *x[2];
   double *A, *B, *C, one = 1.0, zero = 0.0;
  mwSize numDimsA, numDimsB, numDimsC, numPagesA=1, numPagesB =1;
  const mwSize *dimsA=NULL, *dimsB=NULL;
  mwSize *dimsC;
  mwSize strideA, strideB, strideC;
  mwSize m, n, p, pB;
  //ptrdiff_t m, n, p, pB;
  // mwSignedIndex m, n, p, pB;
  char *chn = "N";
  int i=0, PagesFlagA=100,PagesFlagB = 100;

numDimsA = mxGetNumberOfDimensions(prhs[0]);
numDimsB = mxGetNumberOfDimensions(prhs[1]);

dimsA = mxGetDimensions(prhs[0]);
dimsB = mxGetDimensions(prhs[1]);

m = dimsA[0];
p = dimsA[1];

pB = dimsB[0];
n = dimsB[1];

//Calculate number of pages of A
if(numDimsA == 2){
numPagesA = 1;
PagesFlagA = 0; // '0' stands for A is 2-D
}else if(numDimsA > 2){
for(i=2; i<numDimsA; i++){
numPagesA *= dimsA[i];
}
}else{
mexErrMsgTxt("input A and B should not be sclars");
} //end of if

    //Calculate number of pages of B
if(numDimsB == 2){
numPagesB = 1;
PagesFlagB = 0; // '0' stands for A is 2-D
}
else if(numDimsB > 2){
for(i=2; i<numDimsB; i++){
numPagesB *= dimsB[i];
}
};

/*for double check*/
/*mexPrintf("A is %d\t by %d\t by %d \n",dimsA[0], dimsA[1],dimsA[2]);
mexPrintf("B is %d\t by %d\t by %d \n",dimsB[0], dimsB[1],dimsB[2]);*/

if ( p != pB){
mexErrMsgTxt("Inner dimensions of matrix multiply do not match");
}

if ( m != p){
mexErrMsgTxt("A is un-invertable!");
}

strideA = m*p;
strideB = p*n;
strideC = m*n;

m = (ptrdiff_t)(m);
p = (ptrdiff_t)(p);
n = (ptrdiff_t)(n);
 
x[0] = mxCreateDoubleMatrix(m, m, mxREAL);
x[1] = mxCreateDoubleMatrix(m, n, mxREAL);
x[0] = (mxArray*)prhs[0];
x[1] = (mxArray*)prhs[1];

mexCallMATLAB(1, lhs, 2, x, "mldivide");

} // End mexFunction

--------------I have modified code as fellowing --------------------------

x[0] = mxCreateDoubleMatrix(m, m, mxREAL); // add the code today
x[1] = mxCreateDoubleMatrix(m, n, mxREAL); // add the code today
x[0] = (mxArray*)prhs[0];
x[1] = (mxArray*)prhs[1];
 
The code I add to mexFunction correct my last error.

------------- What I will do in the further --------------------------

I confused with How "C" allocation of memory as a starter.
I will carry out my plan by call function in LAPACK/BLAS. Such as DGETRF and DLACN2.

Thanks so much for your kindness.


Lin Renwen

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mexcallmatlab Renwen Lin 5 Aug, 2009 08:06:00
mex Sprinceana 5 Aug, 2009 04:01:08
mldivide Sprinceana 5 Aug, 2009 04:01:04
rssFeed for this Thread

Contact us at files@mathworks.com