Sum specific rows of a 1D wave

I have a 1D wave called data (23,1).

I want to sum specific rows of this wave. In this case, I want variable IVOC to store sum of values in rows (4,8) and SVOC to store sum of rows (9,15). I can't figure out the syntax even though I feel like it has got to be something simple. 

Sumrows returns value for the entire wave so I'm guessing i can't use that.. Kindly help. Thanks!  

Also, please advise on two more things: 

1. How to sum all cells in specific rows of a 2D matrix? i.e. if for a matrix called data1(23,19), I want to produce the sum of all cells that are included in rows 4 to 8.  

2. How to sum all cells of a 2D matrix? i.e. producing the sum of all values in a 2D wave. 

 

Many Thanks and Regards, 

Peeyush

WaveStats/RMD (with /M=0 because you want only the sum):

 

/RMD=[firstRow , lastRow ][firstColumn , lastColumn ][firstLayer , lastLayer ][firstChunk , lastChunk ]
    Designates a contiguous range of data in the source wave to which the operation is to be applied. This flag was added in Igor Pro 7.00.
    You can include all higher dimensions by leaving off the corresponding brackets. For example:
                        /RMD=[firstRow,lastRow]
    includes all available columns, layers and chunks.
    You can use empty brackets to include all of a given dimension. For example:
                        /RMD=[][firstColumn,lastColumn]
    means "all rows from firstColumn to lastColumn".
    You can use a * to specify the end of any dimension. For example:
                        /RMD=[firstRow,*]
    means "from firstRow through the last row".

For the 1D case, in addition to WaveStats, you can use the sum() function like this:

IVOC = sum(data, pnt2x(data, 4), pnt2x(data, 8))

If the wave data has point indexing, you don't need the calls to pnt2x().

Regarding your 2D matrix questions, those are probably best handled with MatrixOP operations. For example, your sum from specific rows could be achieved by:

matrixop/O result=sum(subRange(data,4,8,0,1))

and the answer will be put in the wave "result." Check out the help for the MatrixOP command, there's tons of stuff you can do with it. The same approach could also handle your simpler 1D wave, just need to change the arguments regarding the starting and finishing columns:

MatrixOP/O result=sum(subRange(data,9,15,0,0))
variable SVOC=result[0]

Last, to sum all results in your 2D matrix just don't use the "subrange" part of the above commands.

Thank you so much JimProuty, Johnweeks and Ajleenheer. This was super helpful. Following your suggestions, I've achieved the desired result from the code.