//构建3维矩阵
double*** data3d;//k是最外层(Z),i次外层(y),j是内层(x)
data3d =new double**[volume_depth];
for(int k=0; k<volume_depth; k++)
{
data3d[k] = new double*[volume_height];
for (int i=0; i <volume_height; i++)
data3d[k][i] = new double[volume_width];
}
给矩阵附初值:
//给三维矩阵赋值
for (int k=0; k<volume_depth; k++)
{
for (int i=0; i<volume_height; i++)
{
for (int j=0; j<volume_width;j++)
{
data3d[k][i][j]=0;
data3d1[k][i][j]=0;
}
}
}
www.2cto.com
三维动态数组的空间释放(由内向外):
for(int k=0; k<volume_depth; ++k)
{
for (int i=0; i <volume_height;++i)
{
free(data3d[k][i]);
}
free(data3d[k]);
}
free(data3d);
三维矩阵是按照列顺序存储,先存第一层k=0中的第一列i=0的每个元素j。