如何使用Microsoft Visual C++ 2010 通过 MATLAB 7.10 (R2010a) 创建 MEX
How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?
以下问题:
如何设置 LIBSVM Matlab 接口?
为什么在 r2010a 中键入 mex -setup 时我的 Windows 7 上"没有编译器"?
我遇到了链接:
如何使用 Microsoft Visual C++ 2010 创建带有 MATLAB 7.10 (R2010a) 的 MEX 文件?
页面中说补丁将支持这些组合:
• Visual C++ 2010 Professional and 64-bit MATLAB 7.10 (R2010a)
• Visual C++ 2010 Professional and 32-bit MATLAB 7.10 (R2010a)
• Visual C++ 2010 Express (Windows SDK 7.1 also required) and 64-bit MATLAB 7.10 (R2010a)
• Visual C++ 2010 Express and 32-bit MATLAB 7.10 (R2010a)
但是我的笔记本上Visual C++ 2010 Ultimate
安装了。如何了解修补程序是否支持此组合?
• Visual C++ 2010 Ultimate and 64-bit MATLAB 7.10 (R2010a)
是的,当然。
首先,您应该将包含文件夹,libs文件夹添加到VS include&libs中。
其次,你通过C++实现你的 mex 文件,你应该先将 mex.h 文件包含在你的源代码中,然后 mexFunction 必须根据 mex 的规则提供。如下:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
第三,您应该将库添加到其他依赖项中,例如libmx.lib,libmat.lib,libmex.lib等。
PS:当你尝试实现一个matlab mex项目时,你应该使用VS创建一个dll项目,事实上,mex文件(mexw32和mexw64)是一个特殊的dll文件。所以VS生成的文件是一个dll文件,如果你想让VS生成一个mex文件,你可以通过修改VS项目的配置项来更改文件名,或者在它们生成后重命名文件。
在这里,我只向您展示一些代码:
#include "Rectification.h"
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[] )
{
if (nrhs != 4)
{
mexErrMsgTxt("You need input just 4 parameters!");
}
int m1 = mxGetM(prhs[0]);
int n1 = mxGetN(prhs[0]);
int m2 = mxGetM(prhs[1]);
int n2 = mxGetN(prhs[1]);
int m3 = mxGetM(prhs[2]);
int n3 = mxGetN(prhs[2]);
int m4 = mxGetM(prhs[3]);
int n4 = mxGetN(prhs[3]);
double* temp1 = mxGetPr(prhs[0]);
double* temp2 = mxGetPr(prhs[1]);
double* temp3 = mxGetPr(prhs[2]);
double* temp4 = mxGetPr(prhs[3]);
CMatrix size(m1, n1, temp1);
CMatrix inliers1(m2, n2, temp2);
CMatrix inliers2(m3, n3, temp3);
CMatrix fMatrix(m4, n4, temp4);
CMatrix h1, h2;
CalH(size, inliers1, inliers2, fMatrix, h1, h2);
int om1 = h1.GetmRows();
int on1 = h1.GetmCols();
plhs[0] = mxCreateDoubleMatrix(om1, on1, mxREAL);
double* outMat1 = mxGetPr(plhs[0]);
for (int i = 0; i < om1*on1; i++)
{
*(outMat1 + i) = *(h1.GetmData() + i);
}
int om2 = h2.GetmRows();
int on2 = h2.GetmCols();
plhs[1] = mxCreateDoubleMatrix(om2, on2, mxREAL);
double* outMat2 = mxGetPr(plhs[1]);
for (int i = 0; i < om2*on2; i++)
{
*(outMat2 + i) = *(h2.GetmData() + i);
}
}
如果你需要,我可以和你分享我的项目。
相关文章:
- 使用 MEX 编译C++文件
- 当我运行MEX文件时,MATLAB崩溃
- ASIOSDK;从hostsample.cpp生成mex文件时出错
- 为什么这段代码(在 Matlab 的 MEX 文件中使用 OpenMP)给出不同的结果?
- 索引和访问 mex 函数中单元数组和矩阵的元素
- MEX C++原始数据访问
- 使用 mex 编译库时出错 - __int 64 未命名类型
- 创建 Matlab MEX 函数时,我是否将 mexFunction 放在 c++ 头文件或源文件中
- MEX 文件可以使用 -fsanitize=address 运行吗?
- MEX文件实现特征库伪内函数崩溃
- 为什么用于阈值矩阵元素的 Matlab 逻辑索引操作在性能上优于 mex 实现?
- 从MEX函数中清除MATLAB命令窗口
- 使用带有 MEX 包装器的帮助程序 C 文件从 MATLAB 2016 调用C++代码时出现问题
- 使用 mex 读取和写入文件
- 如何将整数值作为 mex 函数的输入传递?
- MATLAB MEX:-STD = C 11使用,但MEX错误仍然是错误
- 无法生成 mex 文件
- complex_Bessel_function库的编译——与Fortran代码的链接——mex文件
- 如何使用 Boost 库构建 MEX 函数
- 如何使用Microsoft Visual C++ 2010 通过 MATLAB 7.10 (R2010a) 创建 MEX