Simplify large for loop running average.

1 回表示 (過去 30 日間)
curoi
curoi 2015 年 4 月 29 日
回答済み: Ken Atwell 2015 年 4 月 30 日
I'm looking to perform a running average of a height dataset based on conditional time criteria.
First I'm trying to find the overall range of indices that I would perform the running average on:
indi = find( time >= time( 1, 1 ) + hintv );
inde = find( time <= time( end, 1 ) - hintv );
A running average would then be calculated for each cell of time over a 25 hour period (12 hours on either side).
for cc = indi( 1, 1 ):1:inde( end, 1 );
fX( cc, 1 ) = nanmean( height( time >= ( time( cc, 1 ) - hintv ) & ...
time <= ( time( cc, 1 ) + hintv ), 1 ) );
fts( cc, 1 ) = time( cc, 1 );
end
Is there a way of achieving this without having to index each selection of heights within a for loop and then average them?
The problem is that the size of the the time and height datasets for which I would like to get averages are very large, 57000 cells. So a for loop takes way too long.

回答 (1 件)

Ken Atwell
Ken Atwell 2015 年 4 月 30 日
I've used the filter function perform moving average calculations -- seven day data smoothing to remove the effects of weekends in my case. You can find the code toward the end of this blog post.
Hope this helps.

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by