How to calculate moving average in a matrix?

조회 수: 8 (최근 30일)
Andrea Finocchiaro
Andrea Finocchiaro 2015년 10월 8일
댓글: Image Analyst 2017년 4월 7일
Hi Guys, I have got a matrix :378x9. I need to calculate the moving average with a window size of 120(starting from row one). Can somebody help me please? By the way, i need to do it also for the covariance(i mean,"A MOVING COVARIANCE). Thank you very much Andrea
  댓글 수: 2
Joseph Cheng
Joseph Cheng 2015년 10월 8일
is this a window of 120x9 or are you looking to perform the averaging window per column.
Andrea Finocchiaro
Andrea Finocchiaro 2015년 10월 8일
averaging window per column Joseph

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2015년 10월 8일
편집: Image Analyst 2015년 10월 8일
Try conv2:
kernel = ones(120,1)/120;
output = conv2(yourSignal, kernel, 'valid');
Since the window does not leave the boundaries of your signal, of course the output signal will not have as many elements as your input signal.
  댓글 수: 1
Andrea Finocchiaro
Andrea Finocchiaro 2015년 10월 8일
Thank you very much,your code runs very good! Do you think is possible to do the same also to the same for the covariance? I mean to compute the covariance matrix with a window of 120 months?A kind of "moving" covariance . I need these computation because I am working with portdolio optimization(like Markowitz).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Grzegorz Knor
Grzegorz Knor 2017년 4월 7일
From MATLAB R2016a there are functions movmean and movvar which do not require additional toolboxes.
  댓글 수: 1
Image Analyst
Image Analyst 2017년 4월 7일
True, and it offers some edge handling options ('shrink', 'discard', 'fill') that conv2() does not have.
conv2() also does not require any toolboxes because it's in base MATLAB.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by