Reducing number of points in 1 direction of 2D matrix with average
cporaicu
Tue, 06/26/2018 - 08:38 am
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.
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