mwArray a(3, 2, mxDOUBLE_CLASS);为3行2列的矩阵,向其中存储数据时需要用到SetData函数,存储时为列优先存储。示例如下:
// ConsoleApplication2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "mclcppclass.h"
int main()
{
mwArray a(3, 2, mxDOUBLE_CLASS);
double *aData;
aData = new double[6];
int iii;
for (iii = 0; iii<6; ++iii)
{
aData[iii] = iii + 1;
}
// print output
std::cout << "aData = " << std::endl;
std::cout << aData[0] << ",\t" << aData[1] << std::endl;
std::cout << aData[2] << ",\t" << aData[3] << std::endl;
std::cout << aData[4] << ",\t" << aData[5] << std::endl;
a.SetData(aData, 6);//6为向a中存储数据的数量
std::cout << "a(1,1)=" << a(1, 1) << std::endl;
std::cout << "a(1,2)=" << a(1, 2) << std::endl;
std::cout << "a(2,1)=" << a(2, 1) << std::endl;
std::cout << "a(2,2)=" << a(2, 2) << std::endl;
std::cout << "a(3,1)=" << a(3, 1) << std::endl;
std::cout << "a(3,2)=" << a(3, 2) << std::endl;
return 0;
}
输出如下: