关于mwArray和一般数组的区别

时间:2021-05-08 23:51:27

可以用下面的代码详细理解mwArray和一般数组之间的区别

         mwArray a(, ,  mxDOUBLE_CLASS);
double *aData;
aData = new double[];
int iii;
for( iii=; iii<; ++iii)
{
aData[iii] = iii+;
}
// print output
std::cout << "a = " << std::endl;
std::cout << aData[] << ",\t" << aData[] << std::endl;
std::cout << aData[] << ",\t" << aData[] << std::endl;
std::cout << aData[] << ",\t" << aData[] << std::endl; a.SetData(aData, );
std::cout << "a(1,1)="<<a(,)<<std::endl;
std::cout << "a(1,2)="<<a(,)<<std::endl;
std::cout << "a(2,1)="<<a(,)<<std::endl;
std::cout << "a(2,2)="<<a(,)<<std::endl;
std::cout << "a(3,1)="<<a(,)<<std::endl;
std::cout << "a(3,2)="<<a(,)<<std::endl;

运行结果如图:【一位数组到多维数组的组织方式是列优先的】

 a =
,
,
,
a(,)=
a(,)=
a(,)=
a(,)=
a(,)=
a(,)=