From: Kimonas Fountoulakis on
Hi again

I have a matrix A of dimension m x n, and I want to produce a matrix B of dimension m x 2n, in particular I want the following: B = [A -A].

My program so far is:

mxArray *lhs[5];
mxArray *rhs[6];
mxArray *lhs2[1];

rhs[0] = mxCreateDoubleScalar(mxGetScalar(prhs[21]));
rhs[1] = mxCreateDoubleScalar(mxGetScalar(prhs[22]));
rhs[2] = mxCreateDoubleScalar(mxGetScalar(prhs[23]));
rhs[3] = mxCreateDoubleScalar(mxGetScalar(prhs[24]));
rhs[4] = mxCreateDoubleScalar(mxGetScalar(prhs[25]));
rhs[5] = mxCreateDoubleScalar(mxGetScalar(prhs[26]));

mexCallMATLAB(5, lhs, 6, rhs, "getData");

mexCallMATLAB(0, NULL, 1, &lhs[0], "disp");
mexCallMATLAB(0, NULL, 1, &lhs[1], "disp");
mexCallMATLAB(0, NULL, 1, &lhs[2], "disp");
mexCallMATLAB(0, NULL, 1, &lhs[3], "disp");
mexCallMATLAB(0, NULL, 1, &lhs[4], "disp");

mexCallMATLAB(1, lhs2, 1, &lhs[0], "[A -A]"); <--- This is wrong!!

Initially, I call the getData function to produce a matrix and some vectors, hence the lhs[0] holds the matrix that I need in that case. Afterwards, I want to call mexCallMATLAB to produce the new matrix as I said at the beggining. Can anyone help me with the last command??

Thank you in advance!
From: James Tursa on
"Kimonas Fountoulakis" <kfoynt(a)hotmail.com> wrote in message <huo6e1$n0u$1(a)fred.mathworks.com>...
> Hi again
>
> I have a matrix A of dimension m x n, and I want to produce a matrix B of dimension m x 2n, in particular I want the following: B = [A -A].
>
> My program so far is:
>
> mxArray *lhs[5];
> mxArray *rhs[6];
> mxArray *lhs2[1];
>
> rhs[0] = mxCreateDoubleScalar(mxGetScalar(prhs[21]));
> rhs[1] = mxCreateDoubleScalar(mxGetScalar(prhs[22]));
> rhs[2] = mxCreateDoubleScalar(mxGetScalar(prhs[23]));
> rhs[3] = mxCreateDoubleScalar(mxGetScalar(prhs[24]));
> rhs[4] = mxCreateDoubleScalar(mxGetScalar(prhs[25]));
> rhs[5] = mxCreateDoubleScalar(mxGetScalar(prhs[26]));
>
> mexCallMATLAB(5, lhs, 6, rhs, "getData");
>
> mexCallMATLAB(0, NULL, 1, &lhs[0], "disp");
> mexCallMATLAB(0, NULL, 1, &lhs[1], "disp");
> mexCallMATLAB(0, NULL, 1, &lhs[2], "disp");
> mexCallMATLAB(0, NULL, 1, &lhs[3], "disp");
> mexCallMATLAB(0, NULL, 1, &lhs[4], "disp");
>
> mexCallMATLAB(1, lhs2, 1, &lhs[0], "[A -A]"); <--- This is wrong!!

Instead of using multiple mexCallMATLAB calls to do this, you can easily write your own low level code to do it. e.g., (assuming "A" is a real double matrix):

mwSize i, m, n, mn;
double *Apr, *Cpr, *Cminuspr;
:
m = mxGetM(lhs[0]);
n = mxGetN(lhs[0]);
mn = m*n;
lhs2[0] = mxCreateDoubleMatrix(m, 2*n, mxREAL);
Apr = mxGetPr(lhs[0]);
Cpr = mxGetPr(lhs2[0]);
Cminuspr = Cpr + mn;
for( i=0; i<mn, i++ ) {
*Cpr++ = *Apr;
*Cminuspr++ = -(*Apr++);
}


James Tursa
From: Kimonas Fountoulakis on
Thanks once more... it worked perfectly, :-)


"James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <huo7rf$12g$1(a)fred.mathworks.com>...
> "Kimonas Fountoulakis" <kfoynt(a)hotmail.com> wrote in message <huo6e1$n0u$1(a)fred.mathworks.com>...
> > Hi again
> >
> > I have a matrix A of dimension m x n, and I want to produce a matrix B of dimension m x 2n, in particular I want the following: B = [A -A].
> >
> > My program so far is:
> >
> > mxArray *lhs[5];
> > mxArray *rhs[6];
> > mxArray *lhs2[1];
> >
> > rhs[0] = mxCreateDoubleScalar(mxGetScalar(prhs[21]));
> > rhs[1] = mxCreateDoubleScalar(mxGetScalar(prhs[22]));
> > rhs[2] = mxCreateDoubleScalar(mxGetScalar(prhs[23]));
> > rhs[3] = mxCreateDoubleScalar(mxGetScalar(prhs[24]));
> > rhs[4] = mxCreateDoubleScalar(mxGetScalar(prhs[25]));
> > rhs[5] = mxCreateDoubleScalar(mxGetScalar(prhs[26]));
> >
> > mexCallMATLAB(5, lhs, 6, rhs, "getData");
> >
> > mexCallMATLAB(0, NULL, 1, &lhs[0], "disp");
> > mexCallMATLAB(0, NULL, 1, &lhs[1], "disp");
> > mexCallMATLAB(0, NULL, 1, &lhs[2], "disp");
> > mexCallMATLAB(0, NULL, 1, &lhs[3], "disp");
> > mexCallMATLAB(0, NULL, 1, &lhs[4], "disp");
> >
> > mexCallMATLAB(1, lhs2, 1, &lhs[0], "[A -A]"); <--- This is wrong!!
>
> Instead of using multiple mexCallMATLAB calls to do this, you can easily write your own low level code to do it. e.g., (assuming "A" is a real double matrix):
>
> mwSize i, m, n, mn;
> double *Apr, *Cpr, *Cminuspr;
> :
> m = mxGetM(lhs[0]);
> n = mxGetN(lhs[0]);
> mn = m*n;
> lhs2[0] = mxCreateDoubleMatrix(m, 2*n, mxREAL);
> Apr = mxGetPr(lhs[0]);
> Cpr = mxGetPr(lhs2[0]);
> Cminuspr = Cpr + mn;
> for( i=0; i<mn, i++ ) {
> *Cpr++ = *Apr;
> *Cminuspr++ = -(*Apr++);
> }
>
>
> James Tursa
 | 
Pages: 1
Prev: Reading in a matrix
Next: Using MATLAB engine