matlab mex c调用,matlab 生成调用c/c++ 代码 mex 简单实用

目标:在matlab中送入两张图像(矩阵),对图像进行处理,输出为一副图像(矩阵)。

更为详细的用matlab调用c/c++对数组进行处理的例子,

请见下一个博客:  http://blog..net/xiaoyanghijk/article/details/52387089

更为详细的代码下载:http://download..net/detail/xiaoyanghijk/9618136

要熟悉下这个函数的意思:

voidmexFunction(intnlhs, mxArray *plhs[],intnrhs, const mxArray *prhs[])

{

}

Nlhs :输入参数个数

Nrhs:输出参数个数

Plhs[ ]:输入参数列表

Prhs[ ] :输出参数列表

开始动手:

第一步:在matalb 当前目录下放人fun_name.cpp文件。如定义hello.cpp文件在当前路径下:

#include"mex.h"

voidmexFunction(intnlhs, mxArray *plhs[],intnrhs, const mxArray *prhs[])

{

inti;

i=mxGetScalar(prhs[0]);

if(i==1)

mexPrintf("hello,world!\n");

else

mexPrintf("大家好!\n");

}

第二步: 在matalb 窗口执行语句:mex  fun_name.cpp,会生成一个 hello.mexw64  一定要先有这个文件

第三步:执行。

hello(1)

hello,world!

实例2:

void  mexFunction(int  nlhs,  mxArray * plhs[], int nrhs,  const mxArray *prhs[])

{

double *data;

int M,N;

int i,j;

data=mxGetPr(prhs[0]); //获得指向矩阵的指针

M=mxGetM(prhs[0]); //获得矩阵的行数

N=mxGetN(prhs[0]); //获得矩阵的列数

for(i=0;i

{   for(j=0;j

mexPrintf("%4.3f  ",data[j*M+i]);

//mexPrintf("/n");

}

}

a =

1     2     3

4     5     6

7     8     9

10    11    12

>> hello(a)

1.000  2.000  3.000  /n4.000  5.000  6.000  /n7.000  8.000  9.000  /n10.000  11.000  12.000  /n>>

更为详细的用matlab调用c/c++对数组进行处理的例子,请见下一个博客:  http://blog..net/xiaoyanghijk/article/details/52387089

详细代码下载:http://download..net/detail/xiaoyanghijk/9618136

参考链接:

1)http://blog..net/gxiaob/article/details/8679770

2)http://blog..net/jtop0/article/details/7657227

3) http://blog.sciencenet.cn/home.php?mod=space&uid=43777&do=blog&id=320103

4)http://mcximing.github.io/2014/12/12/mex/ matlab 与opencv 混编

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值