MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#" onclick="window._kiq.push(['set', { 'event': 'Turn off MT' }]);">ここ</a>」をクリックしてください。

0

How to calculate moving average in a matrix?

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
2015 年 10 月 8 日
is this a window of 120x9 or are you looking to perform the averaging window per column.
averaging window per column Joseph

サインイン to comment.

2 件の回答

回答者: 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 件のコメント

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).

サインイン to comment.


回答者: Grzegorz Knor 2017 年 4 月 7 日

From MATLAB R2016a there are functions movmean and movvar which do not require additional toolboxes.

  1 件のコメント

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.

サインイン to comment.



Translated by