Sliding window binning and average

Hi all, I have data in a .csv file with two difderent columns and each column has 245438 row. Please kindly help me to find a MATLAB code to bin the first column with a sliding window of 30 and threshold 1 and make an average of corresponding data in second column for each bin.

Respuestas (1)

Mehmed Saad
Mehmed Saad el 20 de Abr. de 2020

0 votos

  1. Read data from csv file using readtable, suppose you store it in variable T and the two column of tables are C1 and C2. To access first column use , T.C1 and for 2nd use T.C2
  2. For sliding window, use conv or filter maybe with (ones(1,30))
  3. After filtering, apply threshold by comparing result of step 2 with threshold i.e 1

6 comentarios

Farshad Daraei Ghadikolaei
Farshad Daraei Ghadikolaei el 20 de Abr. de 2020
Thanks Muhammad for your answer. Actually, I have access to my data in MATLAB. My problem is in binnig part of first column. I need to have a third column in my datasheet, that bin the first column like this: first bin: data no. 1 to data no. 30. Second bin: data no. 2 to data no. 31. Third bin: data no. 3 to data no 33, and so on. After that in a fourth column I need to get average of data in second column corresponding each bin in first column. After that I will plot third column vs fourth column.
Mehmed Saad
Mehmed Saad el 20 de Abr. de 2020
so you mean in third column of your dataset, the size of each row is 30 [1-30,2-31,3-32,.,.]
in fourth column you take average
But how are you suppose to plot 3rd column against 4rth
are you suppose to plot 30 values of 3rd column against 1 value of 4rth column?
Mohammad Sami
Mohammad Sami el 20 de Abr. de 2020
Editada: Mohammad Sami el 20 de Abr. de 2020
"I need to have a third column in my datasheet, that bin the first column like this: first bin: data no. 1 to data no. 30"
Did you mean the first value in third column is the sum of row 1 to 30 of the first column. Or do you want to calculate and average or some other stats ?
Farshad Daraei Ghadikolaei
Farshad Daraei Ghadikolaei el 20 de Abr. de 2020
Yes, the bin size is 30. Each bin should contain: data number of 1-30, 2-31, 3-32, 4-33 and so on. In fourt column I would like the code generate average of data in second column corresponding to each bin of first column. Then I will plot thir column (bin feom first column) vs fourth colum ( average of data of second column).
Farshad Daraei Ghadikolaei
Farshad Daraei Ghadikolaei el 20 de Abr. de 2020
Thanks Muhammad for your contribution. I have developed the answer of Thiago Henrique Gomes: (https://au.mathworks.com/matlabcentral/answers/492847-how-to-create-a-sliding-window-function-over-column-vector-m) to reach what code related to my question.
Mehmed Saad
Mehmed Saad el 21 de Abr. de 2020
Great

Iniciar sesión para comentar.

Categorías

Más información sobre Performance and Memory en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

el 20 de Abr. de 2020

Comentada:

el 21 de Abr. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by