C++调用matlab三维显示mesh/surf

http://blog.csdn.net/u013575812/article/details/51200096

http://stackoverflow.com/questions/215110/scatter-plots-in-c

http://blog.csdn.net/ubunfans/article/details/40040919

http://blog.163.com/rongting_chen/blog/static/164906844201252354518462/

http://www.cnblogs.com/zhangdebin/p/5567929.html

use:http://blog.csdn.net/u010910436/article/details/45919457

http://blog.sina.com.cn/s/blog_7839068101016buh.html

1.环境配置

2.vs配置:不用链接库;matlab配置

3.MATLAB:

>>mex -setup 

>>mbuild –setup 

 mcc -B csharedlib:xxxx xxxx.m

4. C++

4.1 文件中加入 .h .dll .lib

4.2 头文件

 #include "xxxx.h"

#include "engine.h"
#pragma comment( lib, "libeng.lib" )
#pragma comment( lib, "libmx.lib" )
#pragma comment( lib, "libmat.lib" )
#pragma comment( lib, "mclmcrrt.lib" )
#pragma comment( lib, "xxx.lib" )等等

代码:

初始化  showBERInitialize();

调用matlab

关闭 showBERTerminate();

//在英文目录下进行

5.1 整体运行,无需传递参数,matlab配置

#include "nihetest.h"
#include "engine.h"
#pragma comment( lib, "libeng.lib" )
#pragma comment( lib, "libmx.lib" )
#pragma comment( lib, "libmat.lib" )
#pragma comment( lib, "mclmcrrt.lib" )
#pragma comment( lib, "nihetest.lib" )

int main(){


	nihetestInitialize();
	mlfNihetest();//可传递参数
	system("pause");
	nihetestTerminate();


	//
	/*-------------------------静态调用----------------------------------------*/
//1.加载驱动 2.engEvalString(ep,"matlab代码");


	return 0;
	
}

5.2 matlab定义含参函数

http://blog.163.com/rongting_chen/blog/static/164906844201252354518462/

6.matlab输入参数是数组在C++中的使用

matlab中数组的格式是mxArray *m;而c++中二维数组double p[][];因此需要格式转换

matlab代码转换称c++之后,在vs中使用方法:

  mxArray *p = mxCreateDoubleMatrix(100000,3,mxREAL);
  memcpy(mxGetPr(p), result, 10000*3*sizeof(double));//将c的数组复制到matlab的mxArray
  mlfFit(p);//调用matlab函数,p是输入的参数矩阵


你可能感兴趣的:(C/C++,图像处理,Matlab)