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.
@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.
@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.
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.
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]
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]
June 26, 2018 at 09:54 am - Permalink
June 26, 2018 at 11:36 pm - Permalink
Resample
what you are looking for?June 27, 2018 at 12:43 am - Permalink
June 27, 2018 at 12:50 am - Permalink
June 27, 2018 at 12:56 am - Permalink
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
June 27, 2018 at 04:35 am - Permalink
MatrixOp/O/FREE resultW = averageCols(tempMat^t)
This is because the averagecols is not a MatrixOP function. I have changed it toMatrixOp/O/Free resultW = sumcols(tempMat^t)/dimsize(bigwave,1)
but this still did not give me the desired product.June 27, 2018 at 05:19 am - Permalink
// but then you'll need
resultMat[][i] = resultW[p]
June 27, 2018 at 05:27 am - Permalink
June 27, 2018 at 05:28 am - Permalink
June 27, 2018 at 05:45 am - Permalink