Hi guys,

I'm trying to split a binary (only elements are 0 and 1) dynamically allocated 3D array into seperate and smaller 3D arrays. The following figure makes it a bit clearer to understand:

In order to obtain the result, I'm trying to start and allocate new 3D arrays with the right dimensions and filling them. Unfortunately I'm not able to get my dynamic allocation to work for the 'omega_e' array. I want to allocate an array with dimensions [256..511]x[0..511]x[0..85], but I don't know how to do that. Normally you allocate arrays starting with index 0, but I want to start at index 256 and then I want to have the rest of the elements stored in the following indices. A solution would be to allocate an array of 512 elements, but that's not really what I want to do...

Maybe there is another solution to my splitting problem? Any advice would be helpfull!

Thanks in advance!

- MoGuL

Code:int i,j,k; int s = 2; int p = 9; int q = pow(2,s)-1; int dimx = 512; int dimy = 512; int dimz = (pow(2,p)-1)/q; mexPrintf("Unsplit:\n"); mexPrintf("I = [0 .. %i] x [0 .. %i] x [0 .. %i]\n",dimx-1,dimy-1,dimz-1); int vx,vy,f; // Construct the initial binary tridimensional matrix M int ***m; // Dynamically allocate needed memory m = new int**[dimx]; for(i=0; i<dimx; i++){ m[i] = new int*[dimy]; for(j=0; j<dimy; j++){ m[i][j] = new int[dimz]; for(k=0; k<dimz; k++) { //Initialise all elements to zero m[i][j][k]=0; } } } // Fill the tridimensional matrix M with 1's at specific places for(i=0; i<nbVertices; i++) { vx = vertices2[0][i]; vy = vertices2[1][i]; f = ceil(data2[i]/q); // Uniform quantization m[vx][vy][f] = 1; } // Split level #1 // -------------- int dimx_w,dimy_w,dimz_w; int dimx_e,dimy_e,dimz_e; int tmp; //OMEGA_W: i-axis divided, j-axis unchanged, k-axis unchanged dimx_w = floor((dimx-1)/2.0); dimy_w = dimy-1; dimz_w = dimz-1; //OMEGA_E: i-axis divided, j-axis unchanged, k-axis unchanged dimx_e = ceil((dimx-1)/2.0); dimy_e = dimy-1; dimz_e = dimz-1; //OMEGA_W: i-axis divided, j-axis unchanged, k-axis unchanged mexPrintf("I_w = [0 .. %i] x [0 .. %i] x [0 .. %i]\n",dimx_w,dimy_w,dimz_w); //OMEGA_E: i-axis divided, j-axis unchanged, k-axis unchanged mexPrintf("I_e = [%i .. %i] x [0 .. %i] x [0 .. %i]\n",dimx_e,dimx-1,dimy_e,dimz_e); //Initialise needed resources int ***omega_w; int ***omega_e; omega_w = new int**[dimx_w]; for(i=0; i<dimx_w; i++){ omega_w[i] = new int*[dimy_w]; for(j=0; j<dimy_w; j++){ omega_w[i][j] = new int[dimz_w]; for(k=0; k<dimz_w; k++){ //Initialise all elements to zero omega_w[i][j][k]=0; } } } omega_e = new int**[dimx-1-dimx_e]; for(i=dimx_e; i<(dimx-1); i++){ omega_e[i] = new int*[dimy_e]; for(j=0; j<dimy_e; j++){ omega_e[i][j] = new int[dimz_e]; for(k=0; k<dimz_e; k++){ //Initialise all elements to zero omega_e[i][j][k]=0; } } } for(i=0; i<nbVertices; i++) { vx = vertices2[0][i]; if(vx <= dimx_w) { omega_w[vx][vy][f] = m[vx][vy][f]; } else { omega_e[vx][vy][f] = m[vx][vy][f]; } }