Average of selected elements in Matlab

1 Ansicht (letzte 30 Tage)
Hoai An Nguyen
Hoai An Nguyen am 24 Dez. 2020
Kommentiert: weikang zhao am 24 Dez. 2020
I have a data file, first column is Month, second column is Demand. I want to calculate the Moving Average of month 4 (=(month 1+2+3)/3) and so on. Then, I want to display the results in the 3rd column. How can I do?
Instead of using Excel, I want to use Matlab to calculate this. Please help me :(((

Akzeptierte Antwort

weikang zhao
weikang zhao am 24 Dez. 2020
Bearbeitet: weikang zhao am 24 Dez. 2020
easy, use "conv"
x=conv(a(:,2),[1/3,1/3,1/3]);
the first element and the second element of 'x' are useless.
have fun
  4 Kommentare
Hoai An Nguyen
Hoai An Nguyen am 24 Dez. 2020
It has a problem... :(
weikang zhao
weikang zhao am 24 Dez. 2020
opps, 'x' is a column vector
a(:,3)=[nan,nan,nan,x(3:11).'].';

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by