最近在看C++和MATLAB的混合编程,结构体这种复杂的数据类型,通过mwArray传入MATLAB的DLL文件中,是比较复杂的。下面通过一个小程序,来实现结构体转wmArray类型。
VS2010和Matlab2012b混合编程 配置详解见:VS2010和Matlab2012b混合编程
#include<iostream>
#include "MyAddLib.h"
using namespace std;
int main()
{
if(!MyAddLibInitialize())
{
return -1;
}
int a = 1;
int b = 2;
int c = 0;
struct myStruct
{//定义一个结构体
bool flg;
int x;
};
myStruct mys;//声明一个结构体变量
mys.flg = true;//变量赋值
mys.x=10;
const int nfields = 2;//结构体