MATLAB Answers

Running time Average of column values

8 views (last 30 days)
Yash Bhati
Yash Bhati on 19 Oct 2021
Edited: Yash Bhati on 19 Oct 2021
I have to imported data form my simulation and made a table which is of Nx1 size.(N depends on number of output which i get from my simulation)
suppose my Table1 looks likes
1.10
2.20
3.20
4.40
......
now what i want is to create another Table2 which has running average of values from Table1, So my Table2 would look like
1.10
2.(10+20)/2
3.(10+20+20)/3
4.(10+20+20+40)/4
.....

Accepted Answer

KSSV
KSSV on 19 Oct 2021
If A is your column array.
iwant = cumsum(A)./(1:numel(A))
  2 Comments
Yash Bhati
Yash Bhati on 19 Oct 2021
Thank you for your answers. Movmean works well. Code i wrote was this.
t=length(A);
M = movmean(A,[t 0]);
Although script as mentioned by KSSV (iwant = cumsum(A)./(1:numel(A))) works well but had to exract data from diagonal matrix.
Thank you all.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!