Reducing number of points in 1 direction of 2D matrix with average

Hello, I have a 2D matrix with ~ 20000 columns which represent different time intervals. I am looking to change the time intervals through averaging the row values of the matrix in intervals to create a new matrix without changing the size of the matrix in the Y direction. For example, if I could average the rows of every two columns of the 20000 column matrix to obtain a new matrix with 10000 columns [where new column 1 = (average of old column 1 and column 2) and so on...] So far, I have used rowsums and dimsize to obtain an average for the entirety of the rows, but I have not come across anything that allows me to do an interval average and create a new "average value" matrix. Ideally, I would like to create a slider that allows me to change the time scale, i.e. the amount of columns the average is done by, but this is the next step and I first need to figure out how to make an "average value" matrix. I would appreciate any help! Thanks in advance.
You can use Duplicate/R=[value range][value range] or the MatrixOP equivalent redimension().
But that's not what I'm trying to do... I'm not trying to simply redimension the matrix.
@OP: I think what AG means is that you can use either of those two commands to make a new 2D wave and then grab the average of the rows of that new temporary wave as you described. If you write a function to do this in a loop to walk through your big matrix you can do this for whatever interval you want.
sjr51 wrote:
@OP: I think what AG means is that you can use either of those two commands to make a new 2D wave and then grab the average of the rows of that new temporary wave as you described. If you write a function to do this in a loop to walk through your big matrix you can do this for whatever interval you want.
Yes I think that works. Any help on the code would be very much appreciated.
cporaicu wrote:
Yes I think that works. Any help on the code would be very much appreciated.
100% untested but this is what I was thinking
WAVE bigWave // your 20000 column wave
Variable sliderVar=2 // set as 2 but you can set this some other way
Variable nSteps = floor(dimsize(bigWave,1)/sliderVar) // Will not average any leftover columns, e.g. 101st column is slider var is 2.
Make/O/N=(dimsize(bigWave,0),nSteps) resultMat
Variable StartCol,EndCol,i

for(i = 0; i < nSteps; i += 1)
    StartCol = i * sliderVar
    EndCol = StartCol + (sliderVar - 1)
    Duplicate/O/FREE/RMD=[][StartCol,EndCol] bigWave,tempMat
    MatrixOp/O/FREE resultW = averageCols(tempMat^t) // this gives a wave where averages per row are in each column
    resultMat[][i] = resultW[0][p] // assign them to the right column of the result matrix here
endfor
thank you! The code gives me an error at this line: MatrixOp/O/FREE resultW = averageCols(tempMat^t) This is because the averagecols is not a MatrixOP function. I have changed it to MatrixOp/O/Free resultW = sumcols(tempMat^t)/dimsize(bigwave,1) but this still did not give me the desired product.
cporaicu wrote:
thank you! The code gives me an error at this line: MatrixOp/O/FREE resultW = averageCols(tempMat^t) This is because the averagecols is not a MatrixOP function. I have changed it to MatrixOp/O/Free resultW = sumcols(tempMat^t)/dimsize(bigwave,1) but this still did not give me the desired product.
Which Igor version are you using? Anyway, this should work
MatrixOp/O/FREE resultW = sumRows(aa)/numcols(aa)
// but then you'll need
resultMat[][i] = resultW[p]
sjr51 wrote:
cporaicu wrote:
thank you! The code gives me an error at this line: MatrixOp/O/FREE resultW = averageCols(tempMat^t) This is because the averagecols is not a MatrixOP function. I have changed it to MatrixOp/O/Free resultW = sumcols(tempMat^t)/dimsize(bigwave,1) but this still did not give me the desired product.
Which Igor version are you using? Anyway, this should work
MatrixOp/O/FREE resultW = sumRows(aa)/numcols(aa)
// but then you'll need
resultMat[][i] = resultW[p]
It worked thank you!!!!!