【问题标题】:Matlab + Armadillo and the inverse matrix crashesMatlab + Armadillo 和逆矩阵崩溃
【发布时间】:2016-09-16 03:55:59
【问题描述】:

我正在尝试使用 Armadillo lib 从 Matlab 计算逆矩阵。为此,我正在使用 Mex。不幸的是,当我调用该函数时,Matlab 崩溃了。看看我的代码,有人可以帮忙看看我哪里错了?

#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)); 
}

它编译没有错误。

【问题讨论】:

  • 您可以编辑以显示 Matlab 崩溃时看到的错误消息吗?无法判断问题是数字还是代码。

标签: matlab linear-algebra mex armadillo matrix-inverse


【解决方案1】:

试试这个:

#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))); 

}

【讨论】:

    猜你喜欢
    • 2013-02-28
    • 1970-01-01
    • 2022-01-23
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多