Extracting columns from 2D Histogram

I have built a 2D histogram, and I would like to create a function that essentially does the following:

From row 1 to 2, sum the values for every individual column.  Histogram the summed values into a 1D histogram.

I understand the following snippet sums all columns in the matrix, but I'm not sure how to add the condition of a row range.

MatrixOP 1DHist=sumCols(2DWave)

I have attached a picture of the 2D histogram matrix.  For example, for rows 1 to 2, column 1 sums to 0, column 2 sums to -1, and column 3 sums to -1.  I want to store these values in a single wave and histogram them into a 1D Histogram

Thanks in advance.

2D Histogram Matrix

There are a few different ways to do this. One way is to use the Duplicate command with the /RMD flag first and then run the MatrixOp on that. In your case:

Duplicate/O/RMD=[1,2][] The2DWave, TempMatrix
MatrixOp Hist1D = sumcols(TempMatrix)

If you want to do this as a function, you can specify the first and last row as variables using arguments in your function call. Plus, add the /FREE flag to the duplicate command to only temporarily store the tempMatrix.

There is no need to explicitly duplicate the desired range since you can execute the equivalent inside the matrixop command:

MatrixOP/O aa=sumCols(subRange(the2DWave,1,2,0,numCols(the2DWave)-1))

 

... and you may want to transpose the result (add ^t at the end) so it is a simple 1D wave.

 

A.G.