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!