The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: armadillo with mex
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 48
Registered: 12/9/11
armadillo with mex
Posted: Nov 22, 2012 11:25 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Has anyone compiled armadillo with mex? I am have a difficulty compiling successfully.

The code I am using:
#include "mex.h"
#include "math.h"

using namespace arma;

void matlab2arma(mat& A, const mxArray *mxdata){
// delete [] A.mem; // don't do this!
access::rw(A.n_rows)=mxGetM(mxdata); // transposed!

void freeVar(mat& A, const double *ptr){
access::rw(A.n_rows)=1; // transposed!

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (nrhs != 2)
mexErrMsgTxt("Incorrect number of input arguments");
if (nlhs != 1)
mexErrMsgTxt("Incorrect number of output arguments");

mat D1(1,1);
const double* D1mem=access::rw(D1.mem);
matlab2arma(D1,prhs[0]); // First create the matrix, then change it to point to the matlab data.

mat D2(1,1);
const double* D2mem=access::rw(D2.mem);

// check if the input corresponds to what you are expecting
if( D1.n_rows != D2.n_rows )
mexErrMsgTxt("Columns of D1 and D2 must be of equal length!");

if( D1.n_cols != D2.n_cols )
mexErrMsgTxt("Rows of D1 and D2 must be of equal length!");

plhs[0] = mxCreateDoubleMatrix(D1.n_rows, D1.n_cols, mxREAL);
mat output(1,1);
const double* outputmem=access::rw(output.mem);

// output.print();

freeVar(D1,D1mem); // Change back the pointers!!

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.