I'm trying calculate a inverse matrix from Matlab using Armadillo lib. To do this I'm using Mex. Unfortunately, Matlab crashes when I call the function. Looking at my code, someone can help where am I wrong?
#include "armaMex.hpp"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
mat A = armaGetPr(prhs[0]);
plhs[0] = armaCreateMxMatrix(A.n_rows,A.n_cols);
armaSetPr(plhs[0],inv(A));
}
It compiles without errors.
Try this:
#include "armaMex.hpp"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
mat A = conv_to<mat>::from(armaGetPr(prhs[0],true));
plhs[0] = armaCreateMxMatrix(A.n_rows,A.n_cols, mxDOUBLE_CLASS, mxREAL);
armaSetPr(plhs[0],conv_to<mat>::from(inv(A)));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.