Conditioned moving average window
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi everyone, I'm a newbie to Matlab. I'm running a simulation and we're trying to analyse the moving average path length. As in the attached excel, the first column is the time elapsed and the second one is the path length. How do we plot an average moving window of 30 ticks, despite that some time ticks may have more than 1 path length? Thanks.
댓글 수: 0
답변 (1개)
Steven Lord
2017년 7월 13일
If I understand your question correctly, I think you want to use the movmean function with the 'SamplePoints' option.
rng default
t = sort(rand(10, 1));
x = randi(10, 10, 1);
m = movmean(x, [0.25 0.125], 'SamplePoints', t);
results = table((1:10).', t, t-0.25, t+0.125, x, m, ...
'VariableNames', {'row', 't', 't_before', 't_after', 'x', 'movingAverage'})
As an example, consider row 3 of the results table. Row 3's movingAverage should consist of the mean of the values of x in all rows whose t values are between the values of t_before and t_after in row 3. For this sample code, I used rng default so you will receive the same t and x vectors as I did and thus I know that the first three rows contribute to row 3's movingAverage:
results{3, 'movingAverage'} - mean(x(1:3)) % should be 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!