# Copy a values from a 2D wave as 3rd dimension in a 3D wave Hi. I have a 1D wave which I would like to copy into a 3D wave. I can obviously do it with a for loop:

for(i = 0; i < N; i++)
W_3D[i] = W_2D[i]
endfor

however, this should work also as a single line:

`W_3D[] = W_2D[p] //does not work`

but it does not, as it populates all layers with the  value from my W_2D wave. Can you please tell me what am I doing wrong?

Thanks.

Besides learning how to use the wave assignment you may want to use ImageTransform with the keyword setPlane.

To set layer L in a 3D wave with data from a 2D wave you can execute:

`W_3D[][][L] = W_2D[p][q]`

To replace this:

`W_3D[i] = W_2D[i]`

with a wave assignment, do this:

`W_3D[] = W_2D[r]`

This is at first not obvious :) The p,q,r,s functions on the right-hand side refer to the implied loop parameters on the left-hand side. On the left of your assignment, you are iterating through the layers dimension, so you need to use the r function on the RHS. Then you need to put the invocation of r in the dimension you need to access.

Be careful- if there are more layers in the LHS than rows on the RHS, you will get the dreaded Index Out of Range error!

Thank you John. I agree with you, that it is not obvious. My mistake was that instead of W_2D[r] I had W_2D[p], as I was trying to read lines in the W_2D wave and was thinking that "p"/lines is the parameter that refers to the read wave.

It always worked to do this from 2D to 1D wave

`w_2D[] = w_1D[p]`

and was (previously) thinking that p goes over the w_1D. :D

Your suggestion works for going from 2D to 3D waves, and will save me going through loops with other functions as well. From now one will think of p,q,r as referencing the left-sided wave. Thanks again!

You're welcome. Sounds like you've figured out that the correct function p,q,r,s to use on the RHS is set by the position of empty brackets on the LHS. The empty brackets imply a loop over all the elements of a given dimension, so wave0[][][][] is equivalent to

Variable i, j, k, l
for (l = 0; l < maxchunk; l++)
for (k = 0; k < maxlayer; k++)
for (j = 0; j < maxcolumn; j++)
for (i = 0; i < maxrow; i++)
wave0[i][j][k][l] = wave1... some combination of i,j,k,l
endfor
endfor
endfor
endfor

In the wave assignment version (which will run much faster) i,j,k,l are equivalent to p,q,r,s