关于mwArray和一般数组的区别

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

 1         mwArray a(3, 2,  mxDOUBLE_CLASS);  

 2         double *aData;  

 3         aData = new double[6];  

 4         int iii;  

 5         for( iii=0; iii<6; ++iii)  

 6         {  

 7                 aData[iii] = iii+1;  

 8         }  

 9         // print output  

10         std::cout << "a = " << std::endl;  

11         std::cout << aData[0] << ",\t" << aData[1] << std::endl;  

12         std::cout << aData[2] << ",\t" << aData[3] << std::endl;

13         std::cout << aData[4] << ",\t" << aData[5] << std::endl;  

14  

15         a.SetData(aData, 6);  

16         std::cout << "a(1,1)="<<a(1,1)<<std::endl;

17         std::cout << "a(1,2)="<<a(1,2)<<std::endl;

18         std::cout << "a(2,1)="<<a(2,1)<<std::endl;

19         std::cout << "a(2,2)="<<a(2,2)<<std::endl;

20         std::cout << "a(3,1)="<<a(3,1)<<std::endl;

21         std::cout << "a(3,2)="<<a(3,2)<<std::endl;

 

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

 1 a =

 2 1,      2

 3 3,      4

 4 5,      6

 5 a(1,1)=1

 6 a(1,2)=4

 7 a(2,1)=2

 8 a(2,2)=5

 9 a(3,1)=3

10 a(3,2)=6

 

你可能感兴趣的:(array)