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[0][0][i] = W_2D[i][2]
    endfor

however, this should work also as a single line:

W_3D[0][0][] = W_2D[p][2] //does not work

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

 

Thanks.

 

 

the message above should have said: "I have a 2D wave which I would like to copy into a 3D wave"

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]

 

Thank you for trying. Obviously, your suggestion cannot work as the "for" loop.

If the column no. 2 in my 2D wave has values 0,1,2,3, the [0][0][L] should have the same values. So W_3D[0][0][3] should be the same as W_2D[2][3] (in this case equal to 3).

 

 

 

To replace this: 

W_3D[0][0][i] = W_2D[i][2]

with a wave assignment, do this:

W_3D[0][0][] = W_2D[r][2]

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][2] I had W_2D[p][2], 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[][0] = 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