adding multidimensional column to ID wave

I want to add a column of a multidimensional wave to a 1D wave with no success.

 The example below shows the kind of thing I am trying to do.  Normally the multidimensional wave, my6columnArray would be filled with various test data but here I just fill two of the columns with a number.  The loop is where I want to select tests (columns) and add to the 1Dwave.  

 

   make /O/N=(10,6) my6ColumnArray
   
    //  ....  fill columns 0-5 with values from tests
   
    wave array = my6ColumnArray
    array =0
    array[][1] = 7
    array[][5] = -1
   
    make /O/N=10 mywave
    wave my1Dwave = my1Dwave  
    my1Dwave = 0
    variable j
    for (j=0;j<6;j+=1)
        if(j==1 || j==5)             // selected colunms for adding
            my1Dwave += array[][j]  // can't do this!
        endif
    endfor

The manual gives this example 

wave0 = wave0_2D[p][0]                        // Extract column 0 into 1D wave

but I can't seem to translate this .....

 

Hi Mike,

To get some clarity, when you mention you want to add the column to the 1Dwave, do you mean you want to change the 1Dwave to a multidimensional wave by creating a new column in it or do you want to append the data to the end of the 1Dwave increasing its length?

For the first case adding column, you could redimension the wave and then assign the values to the newly created column.

For the latter you could do a concatenate suppressing dimensional promotion (note you could do the first with concatenate also but with restriction of the point numbers in the desired axis need to be the same.  Alternatively to concatenation, you could insert the requisite number of points and then assign the values from the array.  Note: there are some cautions about using concatenate function in loops in the documentation.

 

Andy

Hi Andy,

I don't want to  add another dimension nor to append data on the end of the 1Dwave. 

If I had, say, 'column' 1 of the multiDwave ie. multiDwave[][1] with the following values 0 0 1 1 0 0 0 1 1 1  and 'column' 5 multiDwave[][5] with these values in the 10 'rows'. 2 2 2 0 0 1 -1 0 1 1 and then add these into the 1Dwave and get 2 2 3 1 0 1 -1 1 2 2 for the 10 'rows' respectively. 

I don't talk about this enough to know the correct jargon:-(

Mike: Your example code was one character away from working as you intended.

Change

my1Dwave += array[][j]

to

my1Dwave += array[p][j]

You also need to change the second wave reference statement to

wave my1Dwave = mywave

in order to avoid a run time error.

 

So the finished result looks like this:

Function test()
    make /O/N=(10,6) my6ColumnArray

    //  ....  fill columns 0-5 with values from tests

    wave array = my6ColumnArray
    array =0
    array[][1] = 7
    array[][5] = -1

    make /O/N=10 mywave
    wave my1Dwave = mywave
    my1Dwave = 0
    variable j
    for (j=0;j<6;j+=1)
        if(j==1 || j==5)             // selected colunms for adding
            my1Dwave += array[p][j]  // can't do this!
        endif
    endfor
End

You need the p on the right hand side of the wave assignment statement so Igor knows which point in array to read from.

BTW, you could use MatrixOp to write this is a more understandable way:

Function test()
    make/o/n=(10,6) my6ColumnArray = q
    MatrixOp/O mySum = col(my6ColumnArray, 1) + col(my6ColumnArray,5)
End

 

Hi aclight,

posted before I saw yours - tried it and it worked.  All the clues were there but they didn't click for me.  Thanks.