我在网上找了很多,版本都太老了,每一个用的了的,奇奇怪怪的错误,在同学的帮助调试下终于运行成功一个,贴出来,希望对大家有帮助,调用方法是把m文件生成dll调用的。
m文件如下:
function [output] = test_add(x,y)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
f=imread('C:/distance.bmp');
imshow(f);
output=x+y;
end
vs2008中代码如下:
#include "stdafx.h"
#include "libtest_add.h"
#include
#include
#include
//#include"matlab.hpp"
using namespace std;
//#include"matlab.hpp"
#pragma comment(lib,"mclmcrrt.lib")
#pragma comment(lib,"libtest_add.lib")
int _tmain(int argc, _TCHAR* argv[])
{
//mxArray* pArrayIn;
//mxArray* pArrayOut;
// pArrayIn=mxCreateDoubleMatrix(1,1,mxREAL);//mxREAL实数数组没有虚部,创建一个一行两列的实数数组
// *(mxGetPr(pArrayIn))=10;